霍根JS IF声明 [英] Hogan JS IF statements

查看:90
本文介绍了霍根JS IF声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太喜欢翡翠的语法,想知道我是否可以使用hoganJS做这个简单的比较?



示例代码是用JADE编写的。 / p>

我做了一些搜索,似乎有混合的意见..我只是想知道是否有办法或者我需要改变什么?

 如果用户
li
a(href ='/ dashboard')Dashbaord
li
a ='/ logout')注销
else
li
a(href ='/ login')Logi§n

块体


解决方案

Hogan是 Mustache ,所以使用相同的语法。

  {{#user}} 
< li>< a href =/ dashboard> Dashboard< / a>< / li>
< li>< a href =/ logout>注销< / a>< / li>
{{/ user}}
{{^ user}}
< li>< a href =/ login>登录< / a>< / li>
{{/ user}}

PS我曾经辩论是否使用霍根或一些其他胡须实施在手把上,因为它更快/更轻。我的建议是使用Handlebars不是Hogan,并编译你的前端,并且只使用Handlebars运行时在构建 - 因为它有更好的条件语法,并支持一些更有用的东西,而不是超过顶部。



Handlebars 中,这将是更干净的:

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

但无论如何霍根还是不错,所以你的选择。我也不喜欢玉,它让我想起了CoffeeScript或其他东西。


I don't really like the jade syntax and was wondering if I could do this simple comparison using hoganJS instead?

The example code is written in JADE.

I did some googling and there seems to be mixed opinion.. I just want to know if there is a way or will I need to change something?

if user
 li
   a(href='/dashboard') Dashbaord
 li
   a(href='/logout') Logout
else
 li
   a(href='/login') Logi§n

block body

解决方案

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.

这篇关于霍根JS IF声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆