templates.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Templates
  2. =========
  3. By default, an Admin class uses a set of templates, it is possible to tweak the default values by editing the configuration
  4. .. code-block:: yaml
  5. sonata_admin:
  6. templates:
  7. # default global templates
  8. layout: SonataAdminBundle::standard_layout.html.twig
  9. ajax: SonataAdminBundle::ajax_layout.html.twig
  10. # default values of actions templates, they should extend global templates
  11. list: SonataAdminBundle:CRUD:list.html.twig
  12. show: SonataAdminBundle:CRUD:show.html.twig
  13. edit: SonataAdminBundle:CRUD:edit.html.twig
  14. history: SonataAdminBundle:CRUD:history.html.twig
  15. # default values of helper templates
  16. short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig
  17. Usage of each template :
  18. * layout : base layout used by the dashboard and an admin class
  19. * ajax : default layout used when an ajax request is performed
  20. * dashboard: default layout used at the dashboard
  21. * list : the template to use for the list action
  22. * show : the template to use for the show action
  23. * edit : the template to use for the edit and create action
  24. * history : the template to use for the history / audit action
  25. * short_object_description: used to represent the entity in one-to-one/many-to-one relations
  26. The default values will be set only if the ``Admin::setTemplates`` is not called by the Container.
  27. You can easily extend the provided templates in your own and customize only the blocks you need to change:
  28. .. code-block:: jinja
  29. {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
  30. {# Acme/MyBundle/Ressources/view/my-custom-edit.html.twig #}
  31. {% block title %}
  32. {{ "My title"|trans }}
  33. {% endblock%}
  34. {% block actions %}
  35. <div class="sonata-actions">
  36. <ul>
  37. {% if admin.hasroute('list') and admin.isGranted('LIST')%}
  38. <li class="btn sonata-action-element"><a href="{{ admin.generateUrl('list') }}">{% trans from 'SonataAdminBundle' %}link_action_list{% endtrans %}</a></li>
  39. {% endif %}
  40. </ul>
  41. </div>
  42. {% endblock %}
  43. .. code-block:: php
  44. <?php // MyAdmin.php
  45. public function getEditTemplate()
  46. {
  47. return 'AcmeMyBundle:my-custom-edit.html.twig';
  48. }