How to set comment in jsrender
Asked Answered
A

2

6

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>
Agamemnon answered 20/3, 2013 at 10:11 Comment(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.Hibben
Well, my template is not complex, but do you know why I render this template in example only if data[0] is not empty?Agamemnon
S
9

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

Sacchariferous answered 20/3, 2013 at 17:44 Comment(3)
thx. If I can suggest, you could add list of all tags that could be used in jsrenderer somewhere on web (github.com/BorisMoore/jsrender wiki or in demo page). I only found that there is a {{* javascript code}} tag only on some of the stackoverflow questions.Agamemnon
Yes, now we have reached beta candidate status, so APIs are stable, I will be working towards providing full documentation...Sacchariferous
The documentation now includes all built-in tags. Links added to my post above...Sacchariferous
C
3

There is simple, yet smart trick to use here.

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

Enjoy

Crosseyed answered 20/3, 2013 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.