2

Got next template in separate file section.htm:

<h3>${Name}</h3>
{{each Variables}}
    {{tmpl($data) Type}}
    ${Type} | ${Name} | ${Value}
    <br/>
{{/each}}

I need to render different templates (stored in htm files too) depending on Type. For example, for Type equal to "MultilineText" - MultilineText.htm should be used. Something like: {{tmpl($data) "MultilineText"}}

I already got MultilineText.htm loaded, compiled and cached.

Content of MultilineText.htm:

${Name}<textarea>${Value}</textarea>

But this code doesnt work :(

Please help.

Thanks.

Kirill Salykin
  • 681
  • 6
  • 19

2 Answers2

2

And the answer is {{tmpl($value) $.template[$value.Type]}}

$.template[some_template_name] - with this u can choose what template will be rendered some_template_name - name of template.

Notice that template should be loaded and compiled with $.tmpl before and have some_template_name name.

Kirill Salykin
  • 681
  • 6
  • 19
0

I just ran into the same issue. You can add a call back to compare variables via a callback function.

Take a look at my question: Conditionals in jQuery templates

Community
  • 1
  • 1
locrizak
  • 12,192
  • 12
  • 60
  • 80
  • You are proposing next: {{if GetType() == "MultilineText"}} {{tmpl($data) "MultilineText"}} {{\if}}? I dont think this is good choice, cause i'm planning to have about 10-15 such templates. – Kirill Salykin Jul 06 '11 at 16:12
  • I see you updated you question. Whats the js and the object you have associate with the templates? You'll do this with javascript and should be pretty easy. You should just be able to initiate a template by name or in your case whichever type it is will be the id – locrizak Jul 06 '11 at 17:17