如何在 Twig 模板中转义 Twig 分隔符? [英] How to escape Twig delimiters in a Twig template?

查看:46
本文介绍了如何在 Twig 模板中转义 Twig 分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Twig 使用 {{ }}{% %}{# #} 分隔符.

Twig uses the {{ }}, {% %}, {# #} delimiters.

但是如何在 Twig 模板中显示 {{ }} ?我不是在谈论 HTML 转义.

But how can I display {{ }} in a Twig template? I'm not talking about HTML escaping.

我问这个问题是因为我想在我的 Twig 模板中包含一个 mustache 模板,以便我将填充来自 AJAX 调用的数据.

I ask the question as I want to include a mustache template in my Twig template so that I will fill with data coming from an AJAX call.

推荐答案

最简单的方法是使用变量表达式输出变量分隔符({{):

The easiest way is to output the variable delimiter ({{) by using a variable expression:

{{ '{{' }}

替代方案(当你不得不逃避太多时使用)是原始的(逐字逐句 自 1.12) 块:

Alternatives (used when you have to escape too much) are raw (verbatim since 1.12) blocks:

{% raw %}
    <ul>
    {% for item in seq %}
        <li>{{ item }}</li>
    {% endfor %}
    </ul>
{% endraw %}

实际上,它非常有据可查.

这篇关于如何在 Twig 模板中转义 Twig 分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆