7. TemplatesΒΆ

You can customize the global layout by tweaking the SonataAdminBundle configuration.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# config/packages/sonata_admin.yaml

sonata_admin:
    templates:
        # default global templates
        layout:  '@SonataAdmin/standard_layout.html.twig'
        ajax:    '@SonataAdmin/ajax_layout.html.twig'

        # default value if done set, actions templates, should extend global templates
        list:    '@SonataAdmin/CRUD/list.html.twig'
        show:    '@SonataAdmin/CRUD/show.html.twig'
        edit:    '@SonataAdmin/CRUD/edit.html.twig'

You can also configure the templates used by the Form Framework while rendering the widget

1
2
3
4
5
6
# config/packages/sonata_doctrine_mongodb_admin.yaml

sonata_doctrine_mongodb_admin:
    templates:
        form: ['@SonataDoctrineMongoDBAdmin/Form/form_admin_fields.html.twig']
        filter: ['@SonataDoctrineMongoDBAdmin/Form/filter_admin_fields.html.twig']

You can also customize field types

1
2
3
4
5
6
7
8
# config/packages/sonata_doctrine_mongodb_admin.yaml

sonata_doctrine_mongodb_admin:
    templates:
    types:
        list:
            date:     '@SonataAdmin/CRUD/date_field.html.twig'
            datetime: '@SonataAdmin/CRUD/datetime_field.html.twig'

Note

By default, if the SonataIntlBundle classes are availables, then the numeric and date fields will be localized with the current user locale (only for list, work in progress).

You can also customize field types by adding types in the sonata_doctrine_mongodb_admin.yaml file. The default values are :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# config/packages/sonata_doctrine_mongodb_admin.yaml

sonata_doctrine_mongodb_admin:
    templates:
        types:
            list:
                array:      '@SonataAdmin/CRUD/list_array.html.twig'
                boolean:    '@SonataAdmin/CRUD/list_boolean.html.twig'
                date:       '@SonataAdmin/CRUD/list_date.html.twig'
                time:       '@SonataAdmin/CRUD/list_time.html.twig'
                datetime:   '@SonataAdmin/CRUD/list_datetime.html.twig'
                text:       '@SonataAdmin/CRUD/base_list_field.html.twig'
                trans:      '@SonataAdmin/CRUD/list_trans.html.twig'
                string:     '@SonataAdmin/CRUD/base_list_field.html.twig'
                smallint:   '@SonataAdmin/CRUD/base_list_field.html.twig'
                bigint:     '@SonataAdmin/CRUD/base_list_field.html.twig'
                integer:    '@SonataAdmin/CRUD/base_list_field.html.twig'
                decimal:    '@SonataAdmin/CRUD/base_list_field.html.twig'
                identifier: '@SonataAdmin/CRUD/base_list_field.html.twig'

            show:
                array:      '@SonataAdmin/CRUD/show_array.html.twig'
                boolean:    '@SonataAdmin/CRUD/show_boolean.html.twig'
                date:       '@SonataAdmin/CRUD/show_date.html.twig'
                time:       '@SonataAdmin/CRUD/show_time.html.twig'
                datetime:   '@SonataAdmin/CRUD/show_datetime.html.twig'
                text:       '@SonataAdmin/CRUD/base_show_field.html.twig'
                trans:      '@SonataAdmin/CRUD/show_trans.html.twig'
                string:     '@SonataAdmin/CRUD/base_show_field.html.twig'
                smallint:   '@SonataAdmin/CRUD/base_show_field.html.twig'
                bigint:     '@SonataAdmin/CRUD/base_show_field.html.twig'
                integer:    '@SonataAdmin/CRUD/base_show_field.html.twig'
                decimal:    '@SonataAdmin/CRUD/base_show_field.html.twig'

Note

By default, if the SonataIntlBundle classes are available, then the numeric and date fields will be localized with the current user locale.