templates.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. Usage of each template :
  16. * layout : base layout used by the dashboard and an admin class
  17. * ajax : default layout used when an ajax request is performed
  18. * dashboard: default layout used at the dashboard
  19. * list : the template to use for the list action
  20. * show : the template to use for the show action
  21. * edit : the template to use for the edit and create action
  22. * history : the template to use for the history / audit action
  23. The default values will be set only if the ``Admin::setTemplates`` is not called by the Container.
  24. You can easily extend the provided templates in your own and customize only the blocks you need to change:
  25. .. code-block:: jinja
  26. {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
  27. {# Acme/MyBundle/Ressources/view/my-custom-edit.html.twig #}
  28. {% block title %}
  29. {{ "My title"|trans }}
  30. {% endblock%}
  31. {% block actions %}
  32. <div class="sonata-actions">
  33. <ul>
  34. {% if admin.hasroute('list') and admin.isGranted('LIST')%}
  35. <li class="btn sonata-action-element"><a href="{{ admin.generateUrl('list') }}">{% trans from 'SonataAdminBundle' %}link_action_list{% endtrans %}</a></li>
  36. {% endif %}
  37. </ul>
  38. </div>
  39. {% endblock %}
  40. .. code-block:: php
  41. <?php // MyAdmin.php
  42. public function getEditTemplate()
  43. {
  44. return 'AcmeMyBundle:my-custom-edit.html.twig';
  45. }