2013-03-28 45 views
0

我來自PHP,我可以吧?如果else語句替代語法像骨幹替代語法

<?php if(): ?> 
    // conditional html goes here 
<?php endif;?> 

我的問題是,如果有一種方法可以做同樣的事情中的骨幹視圖像

<% if(condition): %> 
    html code goes here ; 

<% endif; %> 

回答

0

這個問題應該真的用任何模板解決方案進行標記,您使用的骨幹模板解決方案。如果您使用的把手(這是真棒http://handlebarsjs.com/),你可以做到這一點:

{{#if contextPropertyThatEvaluatesSanelyAsABoolean}} 
    your html! 
{{else}} 
    different html! 
{{/if}} 

,然後通過在類似於上下文:

$(@el).html(this.template({ 
    contextPropertyThatEvaluatesSanelyAsABoolean: true 
})) 

,或者如果你正在使用的CoffeeScript:

$(@el).html @template 
    contextPropertyThatEvaluatesSanelyAsABoolean: true 

對於其他模板語言也有類似的解決方案。