0
I am using version 3 of codeigniter and inserting the concept of templates through the PARSER library, according to the CI documentation itself
https://www.codeigniter.com/userguide3/libraries/parser.html
It turns out that in version 2 I use a layout model through a Hook, as this example:
http://flaviosilveira.com/2010/habilitando-layouts-no-codeigniter-template-engine-2/
In the latter the 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, such as header, and footer, changing only the view body.
Already in the case in the parser I still could not understand how to make these calls of includes staticos more usual.
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');
}
}
This would be the best model to work with layouts using PARSER?
The best way would be for the template engine to provide some mechanism to 'assemble' the layout. The code shown in the question seems Boilerplate imagine repeat the calls
parse(), view(), parse()
(roughly there are 3 includes in a rigid order) for all pages, imagine if you had a side menu there would be 4 files called all the time, it is possible to create a method to center the mount.– rray
The idea would be to have a 'main' file that would have 3 'sessions', header, kernel and footer, in the controller vc would only pass the kernel with the data. You can do this without a framework of a look how the Laravel does is cool.
– rray
Exactly this, the repetition of the code would be something extremely tiring and not at all unusual. The blade of the Laravel I think is excellent, and the hook I used in the previous version is very close to that. In case developing a class to make this interaction between the calls of the templates and the insertion of the contents.
– tkmtts
Then I’m gonna take a look at this hook.
– rray
Yes, although I would like to adopt the parser in CI3, and get a little closer to the bucket, I still see the parser as not very intuitive, forced to repeat codes, or use the same logic from hook. Anyway thanks for the help
– tkmtts