# 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.

    <?php
    return array(
        // Layout default settings
        'layout' => 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.

    <?php
    class PagesController extends CController
    {
        public function __construct()
        {
            parent::__construct();
            A::app()->view->setTemplate('frontend');
            A::app()->view->setLayout('wide');
        }
    }

You may also do this in each action separately:

    <?php
    class PagesController extends CController
    {
        public function addAction()
        {
            A::app()->view->setLayout('narrow');
            $this->_view->render('banLists/add');
        }

        public function viewAction()
        {
            A::app()->view->setLayout('wide');
            $this->_view->render('banLists/view');
        }
    }

The common structure of the template directory with layouts looks like following:

- templates/ directory where placed all templates
  - backend/ all public files for backend template
  - default/ all public files for a specific template
  - css css files for template
  - images image files for template
  - js javascript files for template
  - layouts/ all files for layouts
  - .htaccess layouts directory .haccess file
  - default.php layout file
  - wide.php layout file
  - default.php default (master) template file
  - .htaccess templates directory .haccess file

Example of default.php file:

    <!doctype html>
    <html>
    <head>
        <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('http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'); ?>
        <?php echo CHtml::scriptFile('templates/default/js/main.js'); ?>
    </head>
    <body>
        <header>
            <nav>
                <a href="index">Home</a>
            </nav>
        </header>
        <section>
            // Your layout content here
            <?= A::app()->view->getLayoutContent(); ?>
        </section>
        <footer>
            <p class="copyright">Copyright © <?php echo date('Y'); ?> Your Site</p>
            <p class="powered"><?php echo A::powered(); ?></p>
        </footer>
    </body>
    </html>

The layout file looks like following:

    <div class="row">
        <div class="col-lg-8">
            <?= A::app()->view->getContent(); ?>
        </div>
    </div>