templates.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. .. configuration-block::
  5. .. code-block:: yaml
  6. sonata_admin:
  7. templates:
  8. # default global templates
  9. layout: SonataAdminBundle::standard_layout.html.twig
  10. ajax: SonataAdminBundle::ajax_layout.html.twig
  11. dashboard: SonataAdminBundle:Core:dashboard.html.twig
  12. # default values of actions templates, they should extend global templates
  13. list: SonataAdminBundle:CRUD:list.html.twig
  14. show: SonataAdminBundle:CRUD:show.html.twig
  15. edit: SonataAdminBundle:CRUD:edit.html.twig
  16. history: SonataAdminBundle:CRUD:history.html.twig
  17. preview: SonataAdminBundle:CRUD:preview.html.twig
  18. delete: SonataAdminBundle:CRUD:delete.html.twig
  19. batch: SonataAdminBundle:CRUD:list__batch.html.twig
  20. batch_confirmation: SonataAdminBundle:CRUD:batch_confirmation.html.twig
  21. # list related templates
  22. inner_list_row: SonataAdminBundle:CRUD:list_inner_row.html.twig
  23. base_list_field: SonataAdminBundle:CRUD:base_list_field.html.twig
  24. # default values of helper templates
  25. short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig
  26. # default values of block templates, they should extend the base_block template
  27. list_block: SonataAdminBundle:Block:block_admin_list.html.twig
  28. # default values of pager templates
  29. pager_links: SonataAdminBundle:Pager:links.html.twig
  30. pager_results: SonataAdminBundle:Pager:results.html.twig
  31. Usage of each template :
  32. * layout : base layout used by the dashboard and an admin class
  33. * ajax : default layout used when an ajax request is performed
  34. * dashboard: default layout used at the dashboard
  35. * list : the template to use for the list action
  36. * show : the template to use for the show action
  37. * edit : the template to use for the edit and create action
  38. * history : the template to use for the history / audit action
  39. * history_revision_timestamp : the template to use when rendering the timestamp of a given revision
  40. * list_block : the template used for the list of admin blocks on the dashboard
  41. * preview : the template to use for previewing an edit / create action
  42. * short_object_description: used to represent the entity in one-to-one/many-to-one relations
  43. * delete: the template to use for the delete action
  44. * inner_list_row: the template to render a list row
  45. * pager_links: the template to render the first, previous, next and last page links
  46. * pager_results: the template to render the amount of pages, number of results and items per page
  47. The default values will be set only if the ``Admin::setTemplates`` is not called by the Container.
  48. You can easily extend the provided templates in your own template and customize only the blocks you need to change:
  49. .. code-block:: jinja
  50. {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
  51. {# Acme/MyBundle/Resources/view/my-custom-edit.html.twig #}
  52. {% block title %}
  53. {{ "My title"|trans }}
  54. {% endblock%}
  55. {% block actions %}
  56. <div class="sonata-actions">
  57. <ul>
  58. {% if admin.hasroute('list') and admin.isGranted('LIST')%}
  59. <li class="btn sonata-action-element"><a href="{{ admin.generateUrl('list') }}">{{ 'link_action_list'|trans({}, 'SonataAdminBundle') }}</a></li>
  60. {% endif %}
  61. </ul>
  62. </div>
  63. {% endblock %}
  64. .. code-block:: php
  65. <?php // MyAdmin.php
  66. public function getTemplate($name)
  67. {
  68. switch ($name) {
  69. case 'edit':
  70. return 'AcmeMyBundle::my-custom-edit.html.twig';
  71. break;
  72. default:
  73. return parent::getTemplate($name);
  74. break;
  75. }
  76. }
  77. Row Template
  78. ------------
  79. It is possible to completely change how each row of results is rendered in the
  80. list view. For more information about this, see the :doc:`recipe_row_templates`
  81. cookbook entry.