Logic used for layouts in Yii 1.x
Layouts in Yii 1.x may be a little bit mistery to someone, who never worked with some layout framework.
This article tries to explain basics to such people.
Layouts in this folder are named using following schema:
[group]_[type]_[name]
For example: frontend_inner_three_columns
.
Where:
[group]
— stands for side of application (eitherfrontend
orbackend
),[type]
— declares type (inner
oroutter
layout),[name]
— is specific name for a specific action, view or usage scenario.
There are two types of layouts:
- The inner layouts are pieces of HTML code, specific to given action, view or application’s scenario and are injected into outter layouts’ content. They are called in controllers only. Either:
- in base controllers or extenders (by setting
public $layout
) for general purpose layouts or - directly in actions (by specifying
$this->layout
) for a specific situations or scenarios.
- in base controllers or extenders (by setting
- The outter layouts are full-page layouts, containing main HTML code (with doctype and
<head>
section). They’re called inside inner layouts’ files only, using$this->beginContent('//path_to_outter_layout');
.
This split is introduced by core Yii 1.x code and is meant for better readability and re-usability. You can drop it and place entire layout’s HTML code just in outter layout (i.e. the one called by controllers).
But this is highly not recommended way.