私はphpから来ました.elseステートメントのような代替構文を正しくすることができます.
<?php if(): ?>
// conditional html goes here
<?php endif;?>
私の質問は、次のようなバックボーン ビューで同じことを行う方法があるかどうかです。
<% if(condition): %>
html code goes here ;
<% endif; %>
私はphpから来ました.elseステートメントのような代替構文を正しくすることができます.
<?php if(): ?>
// conditional html goes here
<?php endif;?>
私の質問は、次のようなバックボーン ビューで同じことを行う方法があるかどうかです。
<% if(condition): %>
html code goes here ;
<% endif; %>
デフォルトのUnderscore テンプレートを使用している場合:
<% if(condition) { %>
HTML goes here
<% } %>
{
andまたは を忘れないでください}
。めちゃくちゃになってしまいます。
この質問は、バックボーンで使用しているテンプレート ソリューションでタグ付けする必要があります。ハンドルバー (すばらしいhttp://handlebarsjs.com/ ) を使用している場合は、次の方法でそれを行うことができます。
{{#if contextPropertyThatEvaluatesSanelyAsABoolean}}
your html!
{{else}}
different html!
{{/if}}
次に、次のようなコンテキストを渡します。
$(@el).html(this.template({
contextPropertyThatEvaluatesSanelyAsABoolean: true
}))
または、coffeescript を使用している場合:
$(@el).html @template
contextPropertyThatEvaluatesSanelyAsABoolean: true
他のテンプレート言語にも同様のソリューションがあります。