如何在Twig中添加动态HTML标签?

时间:2018-06-29 06:18:44

标签: symfony twig

enter image description here

我想通过html_tag变量更改此h1 HTML标签。我该怎么办?

{% set html_tag = field("html_tag") %}

<h1 class="element-headline">
    <div class="element-headline-text">
        <span class="headline-before-text">{{ before_text }}</span>
        <span class="headline-after-text">{{ after_text }}</span>
    </div>
</h1>

1 个答案:

答案 0 :(得分:2)

{% set html_tag = field("html_tag") %}

<{{html_tag}} class="element-headline">
    <div class="element-headline-text">
        <span class="headline-before-text">{{ before_text }}</span>
        <span class="headline-after-text">{{ after_text }}</span>
    </div>
</{{html_tag}}>

不起作用?