瀏覽代碼

Merge pull request #778 from damienalexandre/add_template_block

Add two empty blocks to the base_edit.html.twig template
Thomas 13 年之前
父節點
當前提交
60d0379f80
共有 2 個文件被更改,包括 34 次插入0 次删除
  1. 30 0
      Resources/doc/reference/templates.rst
  2. 4 0
      Resources/views/CRUD/base_edit.html.twig

+ 30 - 0
Resources/doc/reference/templates.rst

@@ -30,3 +30,33 @@ Usage of each template :
 
 The default values will be set only if the ``Admin::setTemplates`` is not called by the Container.
 
+You can easily extend the provided templates in your own and customize only the blocks you need to change:
+
+.. code-block:: jinja
+
+    {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
+    {# Acme/MyBundle/Ressources/view/my-custom-edit.html.twig #}
+
+    {% block title %}
+        {{ "My title"|trans }}
+    {% endblock%}
+
+    {% block actions %}
+         <div class="sonata-actions">
+             <ul>
+                 {% if admin.hasroute('list') and admin.isGranted('LIST')%}
+                     <li class="btn sonata-action-element"><a href="{{ admin.generateUrl('list') }}">{% trans from 'SonataAdminBundle' %}link_action_list{% endtrans %}</a></li>
+                 {% endif %}
+             </ul>
+         </div>
+    {% endblock %}
+
+
+.. code-block:: php
+
+    <?php // MyAdmin.php
+
+    public function getEditTemplate()
+    {
+        return 'AcmeMyBundle:my-custom-edit.html.twig';
+    }

+ 4 - 0
Resources/views/CRUD/base_edit.html.twig

@@ -57,6 +57,8 @@ file that was distributed with this source code.
                 </div>
             {% endif %}
 
+            {% block sonata_pre_fieldsets %}{% endblock %}
+
             {% for name, form_group in admin.formgroups %}
                 <fieldset {% if form_group.collapsed %}class="sonata-ba-fielset-collapsed"{% endif %}>
                     <legend>
@@ -77,6 +79,8 @@ file that was distributed with this source code.
                 </fieldset>
             {% endfor %}
 
+            {% block sonata_post_fieldsets %}{% endblock %}
+
             {{ form_rest(form) }}
 
             <div class="actions">