Last Updated: February 25, 2016
·
951
· rayfranco

Simple layout support in CodeIgniter 2.0

Simpler could be dangerous for your mental health.

<?php

class MY_Parser extends CI_Parser {

    private $layout = 'main';

    public function set_layout($layout)
    {
        if ( $layout != '' ) {
            $this->layout = $layout;
        }
    }

    public function parse($template, $data, $return = FALSE)
    {
        // First get the normal parsing
        $data['content'] = parent::parse($template, $data, TRUE);

        // Then parse again in the layout, duh !
        return parent::parse('layout/'.$this->layout, $data, $return);
    }
}

/* End of file MY_Parser.php */
/* Location: ./application/libraries/MY_Parser.php */