I have installed Yii2 advanced application, and now I want to change backend theme.
How can I do this?
Is there any file where I need to tell Yii2 that use my custom theme?
I established my theme under backend/web/themes/mytheme
.
I just replaced this code in advanced/backend/config/main.php
, but nothing happened!
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/themes/mytheme'],
'baseUrl' => '@web/themes/mytheme',
],
],
Then I replaced this code under common/config/main.php
but nothing changed!
Yet another approach to change theme in Yii2 is:
Create a themes directory in web folder in frontend or backend where you want to change theme.
place your theme folder inside themes directory.
change $css and $js variables in AppAsset.php in assets folder in frontend or backend like:
Do not include core bootstrap css, bootstrap js and jquery js as these are core APIs that are provided by Yii2. I have commented them above.
Use the below code to reference theme resources (css, js, images etc) in your main.php layout file or other site pages:
There is no need to include css or js files in layouts->main.php file :)
To install a new backend or frontend theme ( I did one page Bootstrap theme), please follow the below steps:
Copy the theme content i.e. directories like js, css, images, fonts etc to for instance backend->web folder.
Change your backend->assets->AppAsset.php class i.e. modify $css and $js arrays like
Please keep in mind to comment out core JQuery and Bootstrap JS files as they are provided by Yii2 by default.
Modify the backend->views->layouts->main.php file as under:
Now adjust your other content pages according to theme, place sections of the theme on your pages that suits you :)
Let me know if anyone comes across any difficulty :)
Create a view folder in your
themes/mytheme
and move all view files likemain.php
into it and other layouts needed.Also you can set your basic layout in the
backend\config\main.php
likeAlso change
pathmap
totry this:
just put all your view folder in themes\mytheme
In the backend folder make a theme folder .In file backend/config/main.php the components section add the code given below ,files in this folder will behave like the view folder in backend .