blueimp/JavaScript-Templates

Calling another template with include

Closed this issue · 1 comments

I realize it's possible to use the include() helper function to reference another template from within a template, but is it possible to pass the included template part of the JSON object used on the original template?

Example: I've got a template that loops through an array of JSON objects with a for loop.

<script id="tmpl-interviews" type="text/x-tmpl">
    {% for (var i = 0; i < o.brief.shot.length; i++) { %}
    ...
    {% include('tmpl-interviewees", o.brief.shot[i]); %}
    ...
    {% } %}
</script>

The included template would loop through a nested array of JSON objects representing interviewees.

<script id="tmpl-interviewees" type="text/x-tmpl">
    {% for (var j = 0, innerCount = j+1; j < o.meta.length; j++, innerCount++) { %}
    // output interviewees
    {% } %}
</script>

Is this even possible in a format like this? I've made the assumption that it's legit to pass the object being used in the root template through to the included template, but it doesn't work for me.

Sure, this should work as expected.
Here's an example that does exactly what you're asking for:
http://jsfiddle.net/aBNpy/