Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig not rendering HTML tags

Tags:

php

twig

symfony

I am using twig as templating engine and i am facing issue while displaying HTML data.

I searched on SO and got following solution

{% autoescape true %} {{ detailArticle.artdesc|raw}} {% endautoescape %}

This expression is working on my localhost but giving problem on cPanel the is Live server.

It is not rendering the output. It is displayed as

<span style="font-size: 12pt; font-family: 'Times New Roman', serif">.. so on

Twig version used is

"twig/twig": "~1.16",

Please suggest

like image 491
Gags Avatar asked Dec 24 '22 06:12

Gags


1 Answers

You're using autoescape, which buffers the contents of that block, and then filters it (escaping HTML entities and so on). If you want to print out a variable that contains markup, use either this:

{{ detailArticle.artdesc|raw }}

Printing the value as a raw string (no escaping at all), or:

{% autoescape false %}
{{ detailArticle.artdesc }}
{% endautoescape %}

Which is the same as using raw on all variables you're using inside that block

like image 82
Elias Van Ootegem Avatar answered Dec 26 '22 18:12

Elias Van Ootegem