Html 细枝中的If语句
可以使用twig语法生成if语句,并根据结果以某种方式关闭html标记。例如:Html 细枝中的If语句,html,symfony,twig,Html,Symfony,Twig,可以使用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<b
<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>
{#如果为false,请关闭按钮标签#}
欢迎
出席
{%else%}
disabled=“disabled”>{#如果为真,则禁用按钮标记,然后关闭#}
欢迎光临
{%endif%}
提前谢谢
-更新-
对不起,我犯了一个愚蠢的错误,我做了正确的事情,但在错误的地方,这就是为什么它没有反映在我的网站上。无论如何,谢谢(:您的代码看起来不错
我的方法是:
<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 %}
{%if someCondition==true%}
欢迎
出席
{%else%}
欢迎光临
{%endif%}
唯一不同的是,如果条件为假,您要做的是禁用按钮?我将删除问题(:我在使用此项的地方出错,这就是我没有在我的网站上看到它的原因。谢谢。嗨,omar,别担心,您解决了吗?是否要更新您的问题?