Error extracting database text

0

With native php I extract from a database a text that contains the typical text, images, videos etc.

I'm migrating the web and I'm using Symfony 2

The content for example of a field in the database is as follows:

<p style="text-align:justify">
    <span style="font-size:14px>hola quetal..etc</span> 
    <img src="servidor"..etc/> 

I do the normal thing I call the controller and he performs a QUERY using the symfony method 2 createQueryBuilder

And in the view I go through the array that the QUERY returns to me:

{% for x in articles1 %}

    <div class="post-article">{{x.texto}}</div>

{% endfor %}   

The problem is that it returns the text, eliminating all the labels so it shows me everything as a

<p>contenido del texto sin importar si tiene mas etiqueta dentro</p>

text without showing bold, images and other links.

Do you know any way that Symfony 2 has to show me things as they are?

    
asked by otacon070 20.10.2016 в 14:12
source

4 answers

0

Also:

You can improve a bit, as well (especially for debug, of course):

{{ x.texto | raw | default("post sin texto") }}

link

You can also configure the autoescape in Twig:

link

    
answered by 24.10.2016 / 12:28
source
1

Twig has the 'safe mode'; that is, the variable can not parse html data directly.

In order to show the complete data, you must use the tag

{% autoescape %}
{{ var|raw }} {# esta variable no será escapada #}
{% endautoescape %}
    
answered by 20.10.2016 в 15:23
1

So that twig does not escape the content of your variables, it is necessary to use the raw filter in this way:

{% for x in articles1 %}
    <div class="post-article">{{x.texto|raw}}</div>
{% endfor %} 
    
answered by 20.10.2016 в 16:23
0

Beware that this tag only works in Twig > = 1.8

link

The fastest way is to use the filter:

{{ x.texto | raw }}

link

    
answered by 24.10.2016 в 12:22