Explorar el Código

Add a safe option for template

Thomas Rabaix hace 12 años
padre
commit
83eb838e13

+ 1 - 1
Resources/views/CRUD/base_show_field.html.twig

@@ -10,4 +10,4 @@ file that was distributed with this source code.
 #}
 
 <th>{% block name %}{{ admin.trans(field_description.label) }}{% endblock %}</th>
-<td>{% block field %}{{ value|nl2br }}{% endblock %}</td>
+<td>{% block field %}{% if field_description.options.safe %}{{ value|raw }}else{{ value|nl2br }}{% endif %}{% endblock %}</td>

+ 5 - 1
Resources/views/CRUD/show_array.html.twig

@@ -13,6 +13,10 @@ file that was distributed with this source code.
 
 {% block field%}
     {% for key, val in value %}
-        [{{ key }} => {{ val }}]
+        {% if field_description.options.safe %}
+            [{{ key }} => {{ val|raw }}]
+        {% else %}
+            [{{ key }} => {{ val }}]
+        {% endif %}
     {% endfor %}
 {% endblock %}

+ 8 - 2
Resources/views/CRUD/show_trans.html.twig

@@ -12,8 +12,14 @@ file that was distributed with this source code.
 
 {% block field%}
     {% if field_description.options.catalogue is not defined %}
-        {{value|trans}}
+        {% set value = value|trans %}
     {% else %}
-        {{value|trans({}, field_description.options.catalogue)}}
+        {% set value = value|trans({}, field_description.options.catalogue) %}
+    {% endif %}
+
+    {% if field_description.options.safe %}
+        {{ value|raw }}
+    {% else %}
+        {{ value }}
     {% endif %}
 {% endblock %}

+ 2 - 0
Show/ShowMapper.php

@@ -81,6 +81,8 @@ class ShowMapper
             $fieldDescription->setOption('label', $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'show', 'label'));
         }
 
+        $fieldDescription->setOption('safe', $fieldDescription->getOption('safe', false));
+
         // add the field with the FormBuilder
         $this->showBuilder->addField($this->list, $type, $fieldDescription, $this->admin);