Im just trying Yii2. Now I have created a yii2 basic appication. Next what I want to do is change the theme. I have an HTML file I want to change this appications theme as like that HTML. I have gone through yii2 theming But Its not what i want I want to add all css,js,images,font of that HTML to my project. How can I do this in yii2 Plz somebody help me.

- 829
- 5
- 15
- 43
-
visit this [link](http://stackoverflow.com/questions/25622565/yii2-theme-integration) – Muhammad Shahzad Apr 08 '16 at 10:04
2 Answers
Hi you have to do following things for theming in yii2 as simple as yii1 :-
- first of all open web.php into config directory of yii2 application,
then in component array pass view array like:
'view' => [ 'theme' => [ 'pathMap' => [ '@app/views' => [ '@webroot/themes/demo/views', ] ], ], ] // here demo is your folder name
now create the folder name as "themes" into web directory.
In this themes folder copy your html folder like(demo) which contains all css, js etc. files. in this folder create views folder as yii which contains main.php and others layouts if needed.
override index.php in views by your corresponding index file by appropriate changes into paths of files. create corresponding views and actions for your html files. in yii2 we can define our css and js into Appasset.php .

- 317
- 3
- 7
-
Thank you for this answer but could you please clarify which index files you mean in your last paragraph? I get lost at 'override'. Thank you :) – mijopabe Nov 18 '14 at 17:05
Hi you need to do a few things to start off.
Copy the new HTML template Css, JS, Plugins and Images into your project directory eg testdrive/assets/
We need to link the CS and Js files to the project. Go to testdrive/protected/views/layouts/ directory and create a new file eg main.php add the respective css and js links to the respective files as you would on a html file in the head section.
<head> <link href="<?php echo Yii::app()->request->baseUrl; ?>/assets/css/style.css" rel="stylesheet"> <title><?php echo CHtml::encode($this->pageTitle); ?></title> </head> <body><? php echo $content ?></body>
3.Once the layout is ready we need to initialise yii to use the layout we have created. Proceed to the Controller eg SiteController.php
public function actionlogin{
$this->layout = 'main';
}
- Now you're set to get your hands dirty.

- 2,840
- 9
- 39
- 52

- 972
- 9
- 27
-
Yes it doesn't work that's why it wasn't marked as an answer this was for yii1 see the answer above it should work also check on a few videos on YouTube on yii2 theming....if you don't manage hit me up I will walk you though – chapskev Feb 12 '16 at 14:27
-
I have been wandering for 3 days to implement a theme in Yii2 Advanced Backend app. But still no success. I had followed videos on Youtube and other blogs but I am unable to get new theme on my CRUD pages. If you have a solution, it will be highly appreciated. – iltaf khalid Feb 12 '16 at 14:50
-
I have sent an invitation on hangout, plz check. Mine is iltafkhalid – iltaf khalid Feb 12 '16 at 15:01