Javascript 如何在细枝模板中放置“if”语句?
所以我用了。像这样:Javascript 如何在细枝模板中放置“if”语句?,javascript,jquery,twig,Javascript,Jquery,Twig,所以我用了。像这样: $.get(base_url+'assets/js/templates/gallery_comment.html', function(template, textStatus, jqXhr) { container.append(Mustache.render($(template).filter('#gallery_comment').html(), data)); }); 要拉入以下胡须模板: <script id="gallery_comment"
$.get(base_url+'assets/js/templates/gallery_comment.html', function(template, textStatus, jqXhr)
{
container.append(Mustache.render($(template).filter('#gallery_comment').html(), data));
});
要拉入以下胡须模板:
<script id="gallery_comment" type="text/html">
{{#has_gallery_comment}}
{{#gallery_comment}}
{{is_active}},
{{is_flagged}},
{{comment}},
{{/gallery_comment}}
{{/has_gallery_comment}}
{{^has_gallery_comment}}
<center><strong>Empty</strong></center>
{{/has_gallery_comment}}
</script>
var data = new Array();
data[gallery_comments] = payload;
data['has_gallery_comments'] = (data.length > 0);
问题:
如何用以下内容替换模板中的{is_-flagged}}语句:
if(is_flagged == 1)
{
echo'is_flagged: YES';
}
else
{
echo'is_flagged: NO';
}
我已经尝试过的:
将其放入模板中不起作用:
{% if is_flagged == 1 %}
is flagged: YES
{% else %}
is flagged: NO
{% endif %}
当你说把这个放在模板中不起作用时,你是什么意思?会发生什么?if语句是否总是等于false?可以尝试{{dumpis_-flagged}}输出is_-flagged变量中实际保存的内容吗。