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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With