简体   繁体   English

Sonata Admin Bundle:更改页面标题

[英]Sonata Admin Bundle : change page title

A little question : how can I change < title > < /title > with Sonata Admin ?一个小问题:如何使用 Sonata Admin 更改<title></title>? 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.您必须覆盖 Sonata 管理员的 standard_layout.html.twig 文件才能实现此目的。

First, define the file in sonata admin config file.首先,在 Sonata 管理配置文件中定义文件。

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.templates/sonata_admin/ 中创建一个名为layout.html.twig 的twig文件,然后粘贴bundle 中的sonata_head_title块。

{% 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 : 1- 在这样的 traslations 中创建文件夹结构:

在此处输入图片说明

2- then in the SonataAdminBundle.[your-language-code].yml file add : 2-然后在SonataAdminBundle.[your-language-code].yml文件中添加:

Admin: "You Custom title Here"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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