Search code examples
jqueryjsrenderjsviews

JSViews - Render flat array data with html


I'm using JSViews and trying to pass to a template an array of strings, some of which will contain html. The template:

{^{for items}}
    <li> {{>#data}} </li>
{{/for}}

My JSON looks something like this:

{ "items": ["<b>Steak</b>", "Cheese"] }

Upon rendering it doesn't bold the word 'steak' but instead prints the <b> tag. I've tried swapping the {{>#data}} for {{:#data}} but that doesn't work either.


Solution

  • You are using the {{>}} tag - which HTML encodes data. If you want the strings to be included in the HTML without HTML encoding, you need to use {{:}}.

    In your case you can write <li>{{:#data}}</li> or simply <li>{{:}}</li>

    See http://www.jsviews.com/#htmltag and http://www.jsviews.com/#assigntag.