By default, an Admin class uses a set of templates, it is possible to tweak the default values by editing the configuration デフォルトでは、Adminクラスはテンプレートセットを使っており、設定を編集することでデフォルト値を変更することができます。
sonata_admin:
templates:
# default global templates
layout: SonataAdminBundle::standard_layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
dashboard: SonataAdminBundle:Core:dashboard.html.twig
# default values of actions templates, they should extend global templates
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
history: SonataAdminBundle:CRUD:history.html.twig
preview: SonataAdminBundle:CRUD:preview.html.twig
# default values of helper templates
short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig
Usage of each template : それぞれのテンプレートの用途
You can easily extend the provided templates in your own and customize only the blocks you need to change:
{% 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 %}
<?php // MyAdmin.php
public function getTemplate($name)
{
switch ($name) {
case 'edit':
return 'AcmeMyBundle::my-custom-edit.html.twig';
break;
default:
return parent::getTemplate($name);
break;
}
}