- Objective: - Breadcrumb: # 概念阐释 ## 语义 在`type="text/x-handlebars-template"`中添加if条件语句。 ## 语法 ```html <script id="ifHelper" type="text/x-handlebars-template"> {{#if argument}} <p>...</p> {{/if}} </script> ``` ```js const context = { argument:true } ``` ### 添加{{else}}表达式 添加当条件为`false`时的代码块 ```html {{else}} ``` ```js const context = { argument: false }; ``` # 实例 在Anki中有类似的用法:如果此字段为空,则不生成这张卡片。 ![](http://image.harryrou.wiki/2023-05-25-CleanShot%202023-05-25%20at%2009.11.30%402x.png) # 相关内容 # 问题 - [练习题1](https://www.codecademy.com/courses/build-interactive-websites/lessons/learn-handlebars/exercises/handlebars-if) 🌟 添加一个opinion的if条件,并添加到‘debate’ id下 🌟 - [练习题2](https://www.codecademy.com/courses/build-interactive-websites/lessons/learn-handlebars/exercises/handlebars-else) 给if条件添加else的内容,`"There's no right way to say GIF!"` # 问题答案 ## 错题集 - 注意`Handlebars.compile( )`的拼写 - 对象不应加标点 # 参考资料