繁体   English   中英

如何在树枝模板中包括已解释文本和未解释文本的混合

[英]How to include mix of interpreted and uninterpreted text in twig template

我正在将细枝与Symfony2框架一起使用。 我还使用嵌入在HTML中的小胡子模板进行客户端渲染(使用javascript)。

在我的Symfony项目中,我正在使用其他树枝模板的砖块构建树枝模板。 使用“包含”功能可以很容易地做到这一点。

当我想在树枝模板中包括一些胡须模板时,可以使用“源”功能,该功能相当于整个模板的“普通”功能。

当我想混合使用已解释和未解释的文本时,会发生我的问题。

例如,我想要解释一条路径,但我不想解释胡子标记。

my_twig_template.html.twig

<body> 
    blablabla
    {{ source('my_mixed_template.html.twig') }}
</body>

my_mixed_template.html.twig

<script type="x-tmpl-mustache" id="my-mixed-template">

    {{ path('path_to_be_interpreted_by_twig') }}

    {{mustache_var_not_to_be_interpreted_by_twig}}    

</script>

任何线索如何做到这一点?

最终,我自己找到了解决方案。

在主树枝模板中:

{% include 'my_mustache_template.html.twig' %}

在树枝模板中嵌入胡子模板:

{% verbatim %}
    <script type="x-tmpl-mustache" id="my-id">
        {{ mustache_variable }}
        {% endverbatim %} {{ twig_variable }} {% verbatim %}
        {{ another_mustache_variable }}
    </script>
{% endverbatim %}

{%endverbatim%} {{twig_variable}} {%verbatim%}序列允许小枝解释器用其实际值替换小枝变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM