Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to override a css of sonata admin bundle in symfony2

i want to override a css file i.e reside in sonata-project/admin-bundle/Sonata/AdminBundle/Resources/public/bootstrap/css path of sonata admin bundle project. Please help me out.

like image 917
Aman Varshney Avatar asked Nov 07 '13 05:11

Aman Varshney


3 Answers

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 %}
like image 149
M Khalid Junaid Avatar answered Nov 09 '22 04:11

M Khalid Junaid


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 %}
like image 23
Thomas Kekeisen Avatar answered Nov 09 '22 03:11

Thomas Kekeisen


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.

like image 4
Denys Horobchenko Avatar answered Nov 09 '22 04:11

Denys Horobchenko