简体   繁体   中英

Sonata Admin Bundle : change page title

A little question : how can I change < title > < /title > with Sonata Admin ? Everywhere there is "Admin...". And when I override a page with sonata template I got "Admin".

在此处输入图片说明

Thank's.

You have to override Sonata admin's standard_layout.html.twig file to achieve this.

First, define the file in sonata admin config file.

config/packages/sonata_admin.yaml

sonata_admin:    
    templates:
        layout: 'sonata_admin/layout.html.twig'

Create a twig file named layout.html.twig inside templates/sonata_admin/ and just paste the sonata_head_title block from the bundle.

{% extends '@SonataAdmin/standard_layout.html.twig' %}

{% block sonata_head_title %}
        {{ 'Admin'|trans({}, 'SonataAdminBundle') }}  //remove this line to get rid of text "Admin"

        {% if _title is not empty %}
            {{ _title|striptags|raw }}
        {% else %}
            {% if action is defined %}
                -
                {% for menu in breadcrumbs_builder.breadcrumbs(admin, action) %}
                    {% if not loop.first %}
                        {% if loop.index != 2 %}
                            &gt;
                        {% endif %}
                        {%- set translation_domain = menu.extra('translation_domain', 'messages') -%}
                        {%- set label = menu.label -%}
                        {%- if translation_domain is not same as(false) -%}
                            {%- set label = label|trans(menu.extra('translation_params', {}), translation_domain) -%}
                        {%- endif -%}

                        {{ label }}
                    {% endif %}
                {% endfor %}
            {% endif %}
        {% endif %}
    {% endblock %}

You can easy do that by override the sonata admin file translation

1- Create folder structure in traslations like this :

在此处输入图片说明

2- then in the SonataAdminBundle.[your-language-code].yml file add :

Admin: "You Custom title Here"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM