Development - Layouts

ApPHP Framework supports layouts for each separate template.

For each application you may define a default layout settings in configuration file. If no layout is defined as default the "default" name will be used.
return array(
    // Layout default settings  
    'layouts' => array(
        'enable' => true, 
        'default' => 'default',			

Sometime we need to use more than one layout in selected template and we need some way to change a layout "on fly". For example we need different templates for Homepage, for Contact Us page, blog post pages etc. The symplest way to do this is to re-define it directly in constructor of appropriate controller.
class PagesController extends CController
    public function __construct()
You may also do this in each action separately:
class PagesController extends CController
    public function addAction()

    public function viewAction()

The common structure of the template directory with layouts looks like following:
Example of default.php file:
<!doctype html>
    <meta charset="UTF-8" />
    <meta name="keywords" content="<?php echo CHtml::encode($this->_pageKeywords); ?>" />
    <meta name="description" content="<?php echo CHtml::encode($this->_pageDescription); ?>" />
    <title><?php echo CHtml::encode($this->_pageTitle); ?></title>    
    <base href="<?php echo A::app()->getRequest()->getBaseUrl(); ?>" />
    <?php echo CHtml::cssFile("templates/default/css/main.css"); ?>
    <?php echo CHtml::scriptFile('//'); ?>
    <?php echo CHtml::scriptFile('templates/default/js/main.js'); ?>
            <a href="index">Home</a>
        // Your layout content here
        <?= A::app()->view->getLayoutContent(); ?>
        <p class="copyright">Copyright © <?php echo date('Y'); ?> Your Site</p>
        <p class="powered"><?php echo A::powered(); ?></p>

The layout file looks like following:
<div class="row">
    <div class="col-lg-8">
        <?= A::app()->view->getContent(); ?>