JsRender Demos

Example Scenario: Inserting "and" and "," separators between words

Example 1: Expressions in tags, and template parameters:
    {{for languages ~count=languages.length}}
        ...
        {{if #index === ~count-2}} and {{else #index < ~count-2}}, {{/if}}
        ...
    {{/for}}
TitleLanguages
Example 2: Custom helper functions:
    {{for languages}}
        ...
        {{if ~nextToLast()}} and {{else ~notLast()}}, {{/if}}
        ...
    {{/for}}
TitleLanguages

Using "allowCode"

Note: The allowCode feature is powerful, but leads to poor separation of concerns, and poor maintainability.
It is therefore only available as an opt-in feature on a per template basis.

The following two examples illustrate its use, but are not the recommended approach. The built-in expression support,
custom tags, helper functions etc. provide a better solution for almost all scenarios, as in the two examples above.
Example 3: allowCode, for program flow:
$.templates( "movieTmpl", {
    markup: "#movieTemplate",
    allowCode: true
});

{{*
    if ( myexpression ) {
}}
    ...
{{*
    }
}}
TitleLanguages
Example 4: allowCode, for returning content:
$.templates( "movieTmpl", {
    markup: "#movieTemplate",
    allowCode: true
});

{{*
    if ( myexpression ) {
        ret += ...;
        ...
    }
}}
TitleLanguages