Sumon Hasan
Sumon Hasan

Reputation: 310

How will i add dynamic HTML tag in Twig?

enter image description here

I want to change this h1 HTML tag by html_tag variable. How will i do it?

{% 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>

Upvotes: 1

Views: 2484

Answers (1)

Jim Panse
Jim Panse

Reputation: 2270

And

{% 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}}>

doesn't work?

Upvotes: 2

Related Questions