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:


For example: frontend_inner_three_columns.

  • [group] — stands for side of application (either frontend or backend),
  • [type] — declares type (inner or outter layout),
  • [name] — is specific name for a specific action, view or usage scenario.

There are two types of layouts:

  1. 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.
  2. 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.

Leave a Reply