A
A
Anchor002015-12-25 15:33:11
Yii
Anchor00, 2015-12-25 15:33:11

YII2: How to make a Module Level Layout?

There is a backend application.
1. Layout, main, application level. The backend has its own, main layout (with doctype, body ...). It lies in backend\views\layouts\main.php . Inside it there is an area, let's say "module content" (like Joomla, it has a template, and inside it is an area for Joomla components). Those. there is a part of the template that does NOT change from module to module (admin menu, admin footer, auxiliary tools at the top).
2. Module Level Layout. Next comes the Module, which should also have a layout, "module level". Those. that part of the module that does NOT change from Controller to Controller (within the module) Eg. module admin menu.
3. Further there is directly view of the Module.
(on the example of Joomla c2n.me/3sdYF2UHighlighted in red - Layout, main, application level. Blue - Module-level Layout. Green - directly the Body of the Module. (Black - the Module itself))
If I set the layout='ModuleLayout' property in the bootstrap class of the Module, then it sets it for the ENTIRE application, as the MAIN one.
Actually a question. How to make this very Module-level Layout in YII2?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Natarov, 2015-12-25
@Anchor00

For a module, the same redefinition as for controllers. In this way. If layout is not overridden for a module, it will use it in the application layer.
for the path @backend/views/layouts/post.php

namespace app\controllers;

use yii\web\Controller;

class PostController extends Controller
{
  //
    public $layout = 'post';
}

And your nesting does not affect anything, you can even do a module in modules ten times, and everything will be different.
Or use nesting for templates. It is described below in the article, on which he gave a link.

A
Alexander, 2015-12-25
@p0vidl0

...
class Module extends \yii\base\Module
{
    ...
    public function init()
    {
        parent::init();
        $this->layout = 'admin';
    }
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question