Theming is not working

I am using yii2.0.30 following is my component configuration to make the application use my theme that has been added under web/themes/my_theme folder :

 'components' => [
        'request' => [
            'cookieValidationKey' => '1asdfsdfsdf4ae69fb3eb71c66441c9458',
        ],
        'db' => require(__DIR__ . '/db.php'),
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false
        ],
        'view' => [
            'theme' => [
                'basePath' => '@web/themes/my_theme',
                'baseUrl' => '@app/themes/my_theme',
                'pathMap' => ['@web/views/layouts' => '@web/themes/my_theme/layouts','@app/views' => '@web/themes/my_theme'],
                
            ],
        ],
        
    ]

my_theme folder has a layouts folder which contain a file called main.php the layout file but the problem is the website is not being render with that layout it is still using the layout inside views/layouts.

What am I doing wrong in this configuration ?

Hi @commun,

You have to use @app for basePath and pathMap, and @web for baseUrl.

'basePath' => '@app/web/themes/my_theme',
'baseUrl' => '@web/themes/my_theme',
'pathMap' => [
    '@app/views' => '@app/web/themes/my_theme'
],
  • @app : the base path of the currently running application. It is the directory where your application is located, e.g. ‘/var/www/myapp’.
  • @web : the base URL of the currently running Web application, it is usually ‘’ (empty string).

Don’t mix up Path and URL. Please check the documentation at Guide > Key Concepts > Aliases > Predefined Aliases.

And I’d rather recommend that you move your view files (including layout) to @app/themes directory and use the following configuration as you see in the guide:

'basePath' => '@app/themes/my_theme',
'baseUrl' => '@web/themes/my_theme',
'pathMap' => [
    '@app/views' => '@app/themes/my_theme'
],

So the directory structure of you app should look like the following:

your_app
    ...
    controllers
    models
    views
        layouts
        site
        ...
    web
        index.php
        css
        js
        images
        ...
        themes
            my_theme
                css
                js
                images
                ...
    themes
        my_theme
            layouts
            site
            ...

Thanks for such well detailed answer.