Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Solution: So in fact the method was right, I have to use the <code>raw</code> filter to get my variable not escaped. I've an <code>autoescape</code> block set that englobe this particular output which is why the reason it has to be "un-escaped".</p> <p>Twig bundle of Symfony 2 provided several block to render form data, and those uses a specific block for attribute rendering called <code>{% block widget_attributes %}</code>.</p> <p>What I did is edit this block (I've a separated template file with all my customized blocks) so I can add a layer of "should this value be escaped or not":</p> <pre><code>{% block widget_attributes %} {% spaceless %} id="{{ id }}" name="{{ full_name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %} {% for attrname,attrvalue in attr %} {# Attribute value can be defined as an array. ['data']: contains the actual value, ['escape']: boolean (true if the value HAS to be escaped)#} {% if attrvalue.data is defined %} {% if not attrvalue.escape %} {{ attrname }}="{{ attrvalue.data|raw }}" {% else %} {{ attrname }}="{{ attrvalue.data|e }}" {% endif %} {% else %} {{ attrname }}="{{ attrvalue }}" {% endif %} {% endfor %} {% endspaceless %} {% endblock widget_attributes %} </code></pre> <p>Called from my twig file:</p> <pre><code>{{ form_widget(form.displays.get('prototype').myField, {'attr': {'value': { 'data': myvalue, 'escape': false } } }) }} </code></pre> <p>The escape is done when printing the value so in the <code>{{ }}</code> twig tag, so what I was doing earlier was sending an unescaped value to a block where the print is actually called and where the value was thus escaped.</p> <p>This works for me! thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload