How to prevent jsrender from creating multiple template instances when model is an array

112 views Asked by At

I am passing an array object as a model to a jsrender template. I would like to render the model using:

{{for ~data}}
<div>{{>Name}}</div>
{{/for}}

However, the default behavior seems to be to render the template for each item of the array automatically. Any way to prevent that that doesn't require changing my data model?

1

There are 1 answers

0
BorisMoore On BEST ANSWER

You can simply wrap your model in an array. Here is a sample that does that:

Sample: Helpers, and layout templates (www.jsviews.com/#samples/jsr/helpers)

var html = $("#movieTemplate").render(
    // Wrap movies array in an array, to render as a layout with header and footer
    [movies],
    helpers
)