html - 如果 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<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/

相关文章:

php - 添加事件类以与 sf2 和 twig 链接

php - 在 Symfony2 和 Twig 中为文件添加资源路径前缀

javascript - Angular url 中的 $locationProvider

css - 使用标记来控制元素的输出。

html - CSS3 翻译 : using percent values

javascript - 如何通过 Twig 中的脚本添加链接路径?

php - "Class XXX is not a valid entity or mapped super class"在文件系统中移动类后

javascript - 使用 twig 日期时间中的日期实现 googlechart x 轴

symfony - 允许 bundle 扩展 Assetic 的 Assets 配置

jquery - 为什么 jQuery 会自动解析我的 data-* 属性?