kabra
kabra

Reputation: 1316

Yii module, theme layout include module layout. How to to that?

I need do something like that:

I have theme "panel" in /themes/panel and there layout /themes/panel/views/layouts/main.php with example content

<a>$content</a>

I have module "admin" in /protected/modules/admin and there layout /protected/modules/admin/view/layouts/main.php with example content

<b>$content</b>

And on the end i want

<a><b>view</b></a>

Also in /themes/panel/views/layouts/main.php i need load css file from module.


In other explanation: I have one template for all panels (header, css files, footer), but each of panels need separate layout (only the middle of content change like menu etc.) and one or more individual css file.

Also some images will be include from main theme, other will be individual for modules.

Upvotes: 0

Views: 3181

Answers (2)

David L
David L

Reputation: 1138

I disagree that in many help forums of the Internet, when someone asks abot theming a module, everyone suggests a path alias to the themes folder. I think this is wrong, because it implies modules to be splitted, and modules are supposed to be a black-box that can be used across projects. The advice given in such forums would only be valid if a theme is shared among several modules. If someone wants to "package" a theme inside a module, she can: -add an init function to the controller of the module -inside that init, use the class attribute layout and a path alias, like this, supose a module whose id is "Sample": then you add, to SampleCOntroller.php:

public function init() {
    //BELOW: it will use the layouts/main.php inside the module.
    $this->layouts = "sample.views.layouts.main"; 
}

Yo can check about path alias here: http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace

Upvotes: 0

FabianoLothor
FabianoLothor

Reputation: 2977

You can use the renderPartial function for load the parts of layout.

<?= $this->renderPartial('webroot.themes.' . Yii::app()->theme->name . '.views.layouts.' . Yii::app()->layout . '.<PART_OF_LAYOUT>') ?>

Upvotes: 1

Related Questions