可以使用 twig 语法进行 if 语句,并根据结果以某种方式关闭 html 标记。例如:
<button name="button" class="btn btn-warning"
{% if someCondition == false %}
> {#if is false close the button tag#}
<i class="fa fa-gift"></i><strong> Welcome<br />Present</strong>
{% else %}
disabled="disabled">{#if is true disable the button tag and then close#}
<i class="fa fa-gift"></i> Welcome<br />Present
{% endif %}
</button>
提前致谢。
-更新-
抱歉,我犯了一个愚蠢的错误,我做的是正确的,但在错误的地方,这就是为什么它没有反射(reflect)在我的网站上。无论如何谢谢(:
最佳答案
您的代码看起来正确。
我的做法:
<button name="button" class="btn btn-warning" {% if someCondition == true %} disabled="disabled" {% endif %}>
<i class="fa fa-gift"></i><strong> Welcome<br />Present</strong>
</button>
如果需要添加强标签,可以添加类:
<button name="button" class="btn btn-warning" {% if someCondition == true %} disabled="disabled" {% endif %}>
<i class="fa fa-gift {% if someCondition == true %} strongClass {% endif %}"></i><strong> Welcome<br />Present</strong>
</button>
你可以这样做:
{% if someCondition == true %}
<button name="button" class="btn btn-warning" disabled="disabled">
<i class="fa fa-gift"></i><strong> Welcome<br />Present</strong>
</button>
{% else %}
<button name="button" class="btn btn-warning">
<i class="fa fa-gift"></i>Welcome<br />Present
</button>
{% endif %}
关于html - 如果 Twig 中的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36029956/