简体   繁体   English

如何在symfony2中覆盖奏鸣曲管理包的CSS

[英]how to override a css of sonata admin bundle in symfony2

i want to override a css file ie reside in sonata-project/admin-bundle/Sonata/AdminBundle/Resources/public/bootstrap/css path of sonata admin bundle project. 我想覆盖一个css文件,即驻留在sonata管理包项目的sonata-project / admin-bundle / Sonata / AdminBundle / Resources / public / bootstrap / css路径中。 Please help me out. 请帮帮我。

One way you can you override the css files of sonata admin but remember this will override the block of stylesheets but still you can call the stylesheets of parent block by calling {{ parent() }} 有一种方法可以覆盖奏鸣曲管理员的css文件,但记住这会覆盖stylesheets块,但你仍然可以通过调用{{ parent() }}来调用父块的stylesheets

{% block stylesheets %}
   /* this will override the parent block you can define here your css files*/
    <link rel="stylesheet" href="{{ asset('cssfilepath.css') }}"/>
{% endblock %}

{% block stylesheets %}
    /*this will extend the parent block */
    {{ parent() }}
    <link rel="stylesheet" href="{{ asset('cssfilepath.css') }}"/>
{% endblock %}

I used the answer of M Khalid Junaid that is working like a charm. 我使用了M Khalid Junaid的答案,就像魅力一样。 Here some facts I missed while implementing this. 这里有一些我在实现这个时错过的事实。

Update your config.yml like this: 像这样更新你的config.yml

sonata_admin:
    templates:
        list: AppBundle::Admin/list.html.twig

The src/AppBundle/Resources/views/Admin/list.html.twig then can look like this: 然后src/AppBundle/Resources/views/Admin/list.html.twig可能如下所示:

{% extends 'SonataAdminBundle:CRUD:base_list.html.twig' %}

{% block stylesheets %}
    {{ parent() }}

    <style type="text/css">
        * {

        }
    </style>

    <!-- and/or -->

    <link rel="stylesheet" href="{{ asset('cssfilepath.css') }}"/>
{% endblock %}

It is possible to remove/add stylesheets in Sonata Admin Bundle within configuration file without handling template files: 可以在配置文件中的Sonata Admin Bundle中删除/添加样式表,而无需处理模板文件:

sonata_admin:
    assets:
        remove_stylesheets:
            - bundles/sonataadmin/css/old.css # path to vendors css-file to remove
        extra_stylesheets:
            - build/admin/css/new.css # your css-file to add

Considered above options are listed in Sonata Admin Bundle CONFIGURATION in FULL CONFIGURATION OPTIONS section. 上面的选项列在FULL CONFIGURATION OPTIONS部分的Sonata Admin Bundle CONFIGURATION中。

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

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