karl2108
karl2108

Reputation: 33

Is there a way to replace a string with html tags in TWIG (Symfony2)?

I have an html saved in my database with a special tag string like [special_tag] and I want to display that html to my twig template at the same time replace the [special_tag] with any html elements.

Is this possible?

Upvotes: 2

Views: 6322

Answers (1)

Crozin
Crozin

Reputation: 44376

Yes, you could use Twig's replace filter:

{{ my_variable_with_html | replace({'[special_tag]': 'new value'}) }}

Upvotes: 3

Related Questions