{"id":29644,"date":"2026-04-10T13:01:15","date_gmt":"2026-04-10T11:01:15","guid":{"rendered":"https:\/\/aivie.ch\/faq\/how-can-i-use-html-in-twig-variables\/"},"modified":"2026-04-10T13:01:23","modified_gmt":"2026-04-10T11:01:23","slug":"how-can-i-use-html-in-twig-variables","status":"publish","type":"faq","link":"https:\/\/aivie.ch\/en\/faq\/how-can-i-use-html-in-twig-variables\/","title":{"rendered":"How can I use HTML in TWIG variables?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You can use HTML in TWIG variables, but you must explicitly allow it using the <code>safe_html<\/code> filter. This ensures security is maintained. <\/p>\n\n<!--more-->\n\n<h2 class=\"wp-block-heading\">Why doesn&#8217;t HTML work directly in TWIG?<\/h2>\n\n<p class=\"wp-block-paragraph\">Aivie has tightened security measures, restricting the processing of HTML in TWIG variables. The reason is that uncontrolled HTML can pose a security risk, for example, through embedded JavaScript or external content. <\/p>\n\n<p class=\"wp-block-paragraph\">Therefore, the following now applies:<\/p>\n\n<ul class=\"wp-block-list\">\n<li>Functions like <code>|raw<\/code> are no longer allowed<\/li>\n\n\n\n<li>No direct HTML tags via tokens<\/li>\n\n\n\n<li>Only secure, controlled output via allowed TWIG functions<\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\">Solution: Use the <code>safe_html<\/code> filter<\/h2>\n\n<p class=\"wp-block-paragraph\">To continue using HTML, a new TWIG filter is available: <code>safe_html<\/code>.<\/p>\n\n<p class=\"wp-block-paragraph\">This filter allows a defined list of secure HTML tags. This way, you can still use structured content such as tables, formatting, or simple layouts. <\/p>\n\n<p class=\"wp-block-paragraph\">The following are not allowed, for example:<\/p>\n\n<ul class=\"wp-block-list\">\n<li>JavaScript<\/li>\n\n\n\n<li>iFrames<\/li>\n\n\n\n<li>Images<\/li>\n\n\n\n<li>External content with potential risk<\/li>\n<\/ul>\n\n<p class=\"wp-block-paragraph\">The allowed HTML elements are based on the official sanitizer list (<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HTML_Sanitizer_API\" target=\"_blank\" rel=\"noreferrer noopener\">MDN HTML Sanitizer API<\/a>).<\/p>\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n<p class=\"wp-block-paragraph\">Here is how you can correctly output HTML in a TWIG variable:<\/p>\n\n<pre class=\"wp-block-code\"><code>&lt;td valign=\"top\" style=\"width: 100%\"&gt;\n  {{ item.name | safe_html }}\n&lt;\/td&gt;\n<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Important: The filter must be applied wherever HTML is expected.<\/p>\n\n<h2 class=\"wp-block-heading\">What else has been improved?<\/h2>\n\n<ul class=\"wp-block-list\">\n<li>Direct viewing and editing of TWIG in the email, landing page, and dynamic content editor<\/li>\n\n\n\n<li>The code editor in the <a href=\"https:\/\/aivie.ch\/en\/product\/mautic-plugin-email-and-landing-page-builder-for-mautic\/\" data-type=\"product\" data-id=\"25135\">Aivie Builder<\/a> now supports TWIG natively (linting, type-ahead, formatting, snippets)<\/li>\n\n\n\n<li>Improved preview of TWIG content<\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n<p class=\"wp-block-paragraph\">HTML tags are possible in TWIG, but only in a controlled manner via the <code>safe_html<\/code> filter. This allows you to combine flexibility with security and avoid risks from insecure code. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use HTML in TWIG variables, but you must explicitly allow it using the safe_html filter. This ensures security is maintained.<\/p>\n","protected":false},"featured_media":0,"template":"","categories":[],"tags":[1763,1762,1760,1761,1759],"FaqCategories":[281,314],"FaqTags":[1757,1758],"class_list":["post-29644","faq","type-faq","status-publish","hentry","tag-code","tag-email-builder","tag-html","tag-landing-page-builder","tag-twig","FaqCategories-emails","FaqCategories-landing-page","FaqTags-code","FaqTags-twig"],"acf":[],"featured_image_urls_v2":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","post-thumbnail":"","aiv_480w":"","woocommerce_thumbnail":"","woocommerce_single":"","woocommerce_gallery_thumbnail":""},"post_excerpt_stackable_v2":"<p>You can use HTML in TWIG variables, but you must explicitly allow it using the safe_html filter. This ensures security is maintained. Why doesn&#8217;t HTML work directly in TWIG? Aivie has tightened security measures, restricting the processing of HTML in TWIG variables. The reason is that uncontrolled HTML can pose a security risk, for example, through embedded JavaScript or external content. Therefore, the following now applies: Functions like |raw are no longer allowed No direct HTML tags via tokens Only secure, controlled output via allowed TWIG functions Solution: Use the safe_html filter To continue using HTML, a new TWIG filter&hellip;<\/p>\n","category_list_v2":"Uncategorized","author_info_v2":{"name":"","url":""},"comments_num_v2":"0 comments","_links":{"self":[{"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/faq\/29644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/types\/faq"}],"version-history":[{"count":1,"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/faq\/29644\/revisions"}],"predecessor-version":[{"id":29645,"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/faq\/29644\/revisions\/29645"}],"wp:attachment":[{"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/media?parent=29644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/categories?post=29644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/tags?post=29644"},{"taxonomy":"FaqCategories","embeddable":true,"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/FaqCategories?post=29644"},{"taxonomy":"FaqTags","embeddable":true,"href":"https:\/\/aivie.ch\/en\/wp-json\/wp\/v2\/FaqTags?post=29644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}