Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do commenting in emberjs script handlebars?

Can anybody tell me how to include commented code in emberjs handlebars templates?

  <script id="restaurantDetail" data-template-name='restaurantDetail' type="text/x-handlebars"> //Commented code goes here </script> 
like image 710
Kapil Garg Avatar asked Mar 27 '12 20:03

Kapil Garg


People also ask

How do you comment in handlebars code?

If you'd like the comments to show up just use HTML comments, and they will be output. Any comments that must contain }} or other handlebars tokens should use the {{! -- --}} syntax.

What is hbs HTML?

An HBS file is a template file created by Handlebars, a web template system. It contains a template written in HTML code and embedded with Handlebars expressions. An HBS file performs the same function as a . HANDLEBARS file.


2 Answers

From the looks of the github page, you want {{! comment text here}}:

Comments

You can add comments to your templates with the following syntax.

{{! This is a comment }} 

You can also use real html comments if you want them to end up in the output.

<div>     {{! This comment will not end up in the output }}     <!-- This comment will show up in the output --> </div> 
like image 125
D.Shawley Avatar answered Nov 10 '22 20:11

D.Shawley


I recommend using {{!-- comment here --}} because this comment syntax can contain new lines and also }} inside the comment, for example:

Bad comments:     {{! badly commented {{if somecondition "red" "blue" }} }}       {{! badly multiline comments         another line  }}    Comment that works:     {{!-- this is commented correctly {{if somecondition "red" "blue" }} --}}     {{!-- correct multiline comments         another line  --}}   

(I know this is an old question, but this answer appears first on Google when searching for ember template comments, so I wanted to help future readers)

like image 35
Iftah Avatar answered Nov 10 '22 19:11

Iftah