JsRender - How to render a template from a template?

How to create a template from a template in JSRender? In the previous jquery template, I could use

{{tmpl(Languages) "#languageTemplate"}}

In JSRender, I could find sample patterns in conditional statements and loops. I want to call the template myself.

+4
source share
2 answers

In JsRender

{{for languages โ€‹โ€‹tmpl = "# languageTemplate" /}}

more or less exactly equivalent to the following in jQuery templates

{{tmpl (Languages) "#languageTemplate"}}

In each case, if Languages โ€‹โ€‹is an array, the Language Template will be displayed once for each element, but if Languages โ€‹โ€‹is not an array, the template will display once.

+6
source

One update for Boris. In Borisโ€™s latest documentation, you need to add "tmpl =" in front of the template name in the for loop to refer to the template in the template. Thus, the final version:

{{for languages โ€‹โ€‹tmpl = "# languageTemplate" /}}

See his demo for more information.

+2
source

Source: https://habr.com/ru/post/1412214/


All Articles