简体   繁体   中英

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. 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() }}

{% 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. Here some facts I missed while implementing this.

Update your config.yml like this:

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

The src/AppBundle/Resources/views/Admin/list.html.twig then can look like this:

{% 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:
    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.

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