Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set comment in jsrender

Tags:

jsrender

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>
like image 944
dugokontov Avatar asked Mar 20 '13 10:03

dugokontov


2 Answers

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

like image 153
BorisMoore Avatar answered Nov 22 '22 18:11

BorisMoore


There is simple, yet smart trick to use here.

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

Enjoy

like image 44
Haris Krajina Avatar answered Nov 22 '22 19:11

Haris Krajina