Ember.js 如何在emberjs脚本手柄中进行注释?
有人能告诉我如何在emberjs Handlebar模板中包含注释代码吗Ember.js 如何在emberjs脚本手柄中进行注释?,ember.js,sproutcore,handlebars.js,Ember.js,Sproutcore,Handlebars.js,有人能告诉我如何在emberjs Handlebar模板中包含注释代码吗 <script id="restaurantDetail" data-template-name='restaurantDetail' type="text/x-handlebars"> //Commented code goes here </script> //注释代码在这里 从外观上看,您需要{{!此处的注释文本}: 评论 您可以使用以下语法向模板添加注释 {{! This is a
<script id="restaurantDetail" data-template-name='restaurantDetail' type="text/x-handlebars">
//Commented code goes here
</script>
//注释代码在这里
从外观上看,您需要{{!此处的注释文本}
:
评论
您可以使用以下语法向模板添加注释
{{! This is a comment }}
如果希望它们最终出现在输出中,也可以使用真正的html注释
<div>
{{! This comment will not end up in the output }}
<!-- This comment will show up in the output -->
</div>
{{!此注释不会在输出中结束}
我建议使用
{{!--comment here-->
,因为此注释语法可以在注释中包含新行和}
,例如:
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 --}}
(我知道这是一个老问题,但这个答案在搜索ember模板注释时首先出现在Google上,所以我想帮助未来的读者)此外,如果您使用的是真正的html注释,并且希望包含变量,请确保使用
注释必须位于自己的{{}容器还是允许它们内联,例如{name!这是App.controller.content.name}?这绝对是一个好办法,在学习Ember的过程中帮了我很大的忙(只需确保不要在模板中乱放注释掉的代码:))这可能是在以后的版本中添加的?因为公认的答案是从2012年开始的,这是从2015年开始的