1

I am using Yii2 Advanced Template. I have created user module inside /frontend/modules/ directory. without theme integration, views are called from /modules/user/views/ directory.

Currently, I have created three different themes inside /frontend directory. So I would like to access views from theme directory for User Module. How it would be possible?

It is possible to set layout for module by

$this->layoutPath = \Yii::getAlias('/themes/classic/views/layouts/');

$this->layout = 'userLayout';

But How views can be accessed from theme directory for module?

Please suggest possible solutions..

TechCompose
  • 53
  • 1
  • 8
  • Did you tried setting the layoutPath and layout? It worked or you are getting some error? Please specify. – Chinmay Waghmare Mar 25 '15 at 05:42
  • It is working for me but views are rendering from modules/view directory. I want to render views from theme directory which is in /frontend/theme/classic. – TechCompose Mar 25 '15 at 06:27
  • Try setting your paths with these methods: setLayoutPath() and setViewPath() For morde details check this link: http://www.yiiframework.com/doc-2.0/yii-base-module.html – Chinmay Waghmare Mar 25 '15 at 06:48
  • Try this answer http://stackoverflow.com/questions/25622565/yii2-theme-integration/32659605#32659605 – Midhun Sep 18 '15 at 19:27

1 Answers1

2

I found solution to my question. I have implemented following way.

Added Layout path in Module.php after init() method.

public function init()
{
    parent::init();
    $this->layoutPath = \Yii::getAlias('@app/themes/classic/views/layouts/');
    $this->layout = 'userLayout';
}

and

added theme configuration with module views in main.php config file

'view' => [
        'theme' => [
          'pathMap' => [
              '@app/views' =>'@app/themes/classic/views/',
              '@app/modules'=>'@app/themes/classic/modules',
              '@app/widgets'=>'@app/themes/classic/widgets'

          ],
          'baseUrl'=>"/themes/classic",
        ],
    ],
TechCompose
  • 53
  • 1
  • 8