What is the best way to use templates in Codeigniter 3

1

I'm using version 3 of codeigniter and inserting the concept of templates through the PARSER library, according to the CI's own documentation

link

It turns out that in version 2 I use a layout model through a Hook, as in this example:

link

In this last use was simpler because in Hook I already had the definition of which part of the block would the content of my view, ie making the includes of the static parts, like header, and rodape, changing only the body of the view.

In the parser case I still can not figure out how to make these static calls in a more usual way.

It would be something like:

class Home extends CI_Controller {

       public function index() {     
            $data = array(
                       'blog_title' => 'My Blog Title',
                        'title' => 'My Title'
                     );
            $row['nome'] = $this->session->userdata('nome');
            $this->parser->parse('templates/cabecalho', $row);
            $this->load->view('welcome_message');
            $this->parser->parse('templates/rodape');
        }
}

Would this be the best template for working with layouts using PARSER?

    
asked by anonymous 24.05.2016 / 17:27

1 answer

1

I particularly like to use it this way:

public function _site($view) {

    $this->load->vars($this->dados);
    $this->load->view('view_topo');      
    if (is_array($view)) {
        foreach ($view as $valor) {
           $this->load->view($valor);
        }
    } else {
        $this->load->view($view);
    }     
    $this->load->view('view_rodape');       
}

In this case, I call the controller:

    $dados['vantagems'] = $this->model_vantagem->get_vantagem_lista();
    $this->load->vars($dados); // Load nas variaveis que eu preciso usar na view
    $this->_site(array('view_vantagem'));

Maybe it will help you too!

    
24.05.2016 / 17:57