Answer the question
In order to leave comments, you need to log in
How to use theming in modules?
Colleagues, good afternoon.
I'm switching to yii2. There was a question with theming in modules.
The desire is to have a themes folder, store various templates in it, have a modules folder in the templates and, according to the names of modules and controllers, views.
I collect everything manually, without using gii.
Config:
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@webroot/themes/basic/views'],
'baseUrl' => '@web/themes/basic',
],
],
namespace app\modules\site\controllers;
use Yii;
use app\models\Post;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class DefaultController extends Controller
{
public function init()
{
parent::init();
}
public function actionIndex()
{
$this->render('index', []);
}
}
Invalid Parameter - yii\base\InvalidParamException
The view file does not exist: /var/www/yii2/modules/site/views/default/index.php
Answer the question
In order to leave comments, you need to log in
As an option:
<?php
namespace app\modules\dashboard;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\dashboard\controllers';
public function init()
{
parent::init();
$theme = ''; // Yii::$app-> ... как-то тут можно вытащить название темы которая сейчас установлена
$this->viewPath = '@app/themes/'.$theme.'/modules/'. $this->id ;
// custom initialization code goes here
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question