Bladeren bron

Add a note about templates extending in the documentation

Damien Alexandre 13 jaren geleden
bovenliggende
commit
0f53784ed8
1 gewijzigde bestanden met toevoegingen van 30 en 0 verwijderingen
  1. 30 0
      Resources/doc/reference/templates.rst

+ 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';
+    }