twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

Question : how to compare keyvalue's with hogan? #160

Closed sackIndian closed 10 years ago

sackIndian commented 10 years ago

Hi, How can i achieve

if(v1 == "somestring") { }

this with hagan.js?

Thanks in advance.

nemtsov commented 10 years ago

The mustache docs may help. Specifically sections and inverted sections.

sackIndian commented 10 years ago

Hello @nemtsov, i am wondering wether is it possible to use switch cases with hogan.

You can take a look at my senario: [ {"type" : "1", "detail" : "my detail"}, {"type" : "2", "detail" : "my detail"}, {"type" : "2", "detail" : "my detail"}, ]

Here as mustache docs, i can do something like [{"type1" : true, ...} ], but with this each time i need to change my json key while constructing my json. It is little problematic for me.

nemtsov commented 10 years ago

@sackIndian mustache by its definition is a logic-less template. In practice that means only boolean logic. So, you can't check for a specific type, but can check for existence of a property. This is by design. Take a look at this SO question for the reasons.

Also, this discussion doesn't really belong in Hogan, as your question is about mustache in general, so you may want to close it and move it to Stack Overflow, if you're still not happy with the answer.

sackIndian commented 10 years ago

Thanks @nemtsov.