6
votes

When I use jsrender template engine, I want to put some comment in code, but I couldn't find tag for comments.

I know that I can use html comments, but I don't want those comments to be rendered on html at all, so <!-- --> is out of option.

So, what I want to have is:

<script id="row-template" type="text/x-jsrender">
{{// some comment that will not be rendered}}
{{if #data[0]}}
  <tr>
    {{for #data tmpl="#some-template"/}}
  </tr>
{{/if}}
</script>
2
I'm curious why a comment in the template is even necessary. If your template is so complex that it warrents comments to explalin it, maybe you should reevaluate how your template is constructed. - Stephen Collins
Well, my template is not complex, but do you know why I render this template in example only if data[0] is not empty? - dugokontov

2 Answers

9
votes

There is a comment syntax in JsRender {{!-- this is a comment --}}.

It works also as multi-line, so you can comment out sections of JsRender markup. It is completely eliminated from the output, so it will not find its way into the DOM (unlike HTML comments).

See http://www.jsviews.com/#commenttag.

For the complete list of built-in tags, see: http://www.jsviews.com/#jsrtags

3
votes

There is simple, yet smart trick to use here.

{{if false}}
   This is my comment.
   It can be multi-line comment.
{{/if}}

Enjoy