소스 검색

Add a safe option for template

Thomas Rabaix 12 년 전
부모
커밋
83eb838e13
4개의 변경된 파일16개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      Resources/views/CRUD/base_show_field.html.twig
  2. 5 1
      Resources/views/CRUD/show_array.html.twig
  3. 8 2
      Resources/views/CRUD/show_trans.html.twig
  4. 2 0
      Show/ShowMapper.php

+ 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);