Hogan JS IF statements

吃可爱长大的小学妹 提交于 2019-12-05 02:09:35

Hogan is an implementation of Mustache so the same syntax applies.

{{#user}}
  <li><a href="/dashboard">Dashboard</a></li>
  <li><a href="/logout">Logout</a></li>
{{/user}}
{{^user}}
  <li><a href="/login">Login</a></li>
{{/user}}

PS I used to debate whether to use Hogan or some other Mustache implementation over Handlebars because it was little faster/lighter. My advice is to use Handlebars not Hogan, and compile your front end and only use Handlebars runtime on build - because it has nicer conditional syntax and supports a few more useful things without going too over the top.

In Handlebars it would be the cleaner:

{{#if user}}
...
{{else}}
...
{{/if}

But anyway Hogan is still nice, so your choice. I also don't like Jade it reminds me of CoffeeScript or something.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!