Layout

Navigation:  Development > MVC (Model View Controller) > View > Theme >

Layout

Previous pageReturn to chapter overviewNext page

Layout is common template that load for all pages. It basically combine all other pieces of template and create the final output. It plays a major role in a theme. Each time we browse a page the layout file runs automatically.
 
We place all layouts in below location
 
/development/view/[theme]/layout/

 

Below are the common roles of a layout

1.Load Action Template content.

2.Select proper layout based on instruction of Action Method.

3.Load page Meta information.

4.Load Addons Resource.

5.Load Theme CSS.

6.Load Dynamic CSS and JavaScript.

7.Render other elements(Header, Footer).

8.Example

 

By default system load default.phtml layout. It is basically a HTML Template file. For example you can open below file
 

/development/view/rainbow/layout/default.phtml

 

Load Action Template content

Layout fetch full executed content of Action Template and render. This content saved in following variable

 

$content_rendered

 

Select Proper Layout

Layout can change from action method. Action Method has below special variable for layout selection.
 
$this->layout

 

By default system load default.html, But we can change like 
 
$this->layout = 'layout2';
$this->layout = 'onecollayout'; etc. 
 
For new layout we have to create new file in like layout2.phtml or onecollayout.phtml in layout folder.

 

There are some special layout
 

Parameter

Description

default

Set default theme

admin

Set Admin Panel Theme

blank

Load Action Template only

empty

Unload all templates

 

Load page Meta information:
Layout always set Set Meta Options of a page. Meta information set by calling below elements
 
echo $this->callElement("header_info");

 

Load Addons Resource

All 3rd addons resource load by below method:

 
$this->fetchAddonlibs();

 

Load Theme CSS

Most of the time we attached the theme CSS in layout from theme directory like below:
 

<link href="<?php echo $this->skinurl("/css/reset.css");?>" rel="stylesheet" type="text/css" media="all"/>
<link href="<?php echo $this->skinurl("/css/default.css");?>" rel="stylesheet" type="text/css" media="all"/>

 

Load Dynamic CSS and JavaScript

Each theme has two special action template to load dynamic JavaScript and CSS. We call those template from layout like below 
 
<link href="<?php echo $this->baseurl("/common/default-css");?>" rel="stylesheet" type="text/css" media="all"/>
<script type="text/javascript" src="<?php echo $this->baseurl("/common/default-js");?>"></script>

 

Render other Elements
One of the Major Task of layout is rendering other Elements. Template can render inside layout from other path. Most commonly we do it for Header and Footer to keep it common for all pages. See below example:
 
echo $this->callElement("header");
echo $this->callElement("footer");

 

Example:

See below example of a layout: 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <?php App::Hook('UI')->Render('template_head_tag_start'); #User Interface Hook ?>
        <?php echo $this->callElement("header_info"); ?>
 
        <!-- Load by addons -->
        <?php $this->fetchAddonlibs();?>
 
        <!-- Static -->
        <link href="<?php echo $this->skinurl("/css/reset.css");?>" rel="stylesheet" type="text/css" media="all"/>
        <link href="<?php echo $this->skinurl("/css/default.css");?>" rel="stylesheet" type="text/css" media="all"/>
    
       <!-- Dynamic -->
       <link href="<?php echo $this->baseurl("/common/default-css");?>" rel="stylesheet" type="text/css" media="all"/>
       <script type="text/javascript" src="<?php echo $this->baseurl("/common/default-js");?>"></script>
        <?php App::Hook('UI')->Render('template_head_tag_end'); #User Interface Hook ?>
    </head>
    <body>
        <div class="container_16">
            <?php  echo $this->callElement("header"); ?>
            <?php echo $content_rendered;?>      
            <?php echo $this->callElement("footer"); ?>
        </div>
    </body>
</html>