CodeIgniter Forums
site inside enclosing html - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: site inside enclosing html (/showthread.php?tid=38553)



site inside enclosing html - El Forum - 02-11-2011

[eluser]Unknown[/eluser]
Hi.

I was wondering, is there a way to place down a markup on every page, regardless of the controller, and than load the views inside that? So, for example I can create a wrapper div for my site, and than load the necessairy views inside that.


site inside enclosing html - El Forum - 02-11-2011

[eluser]Pedro Luz[/eluser]
i dont know if i did understand want you want

but you can use a kind of template

Code:
// the view that you want to load
$data["main_content"] = "/foobar_list";

// load the template base and pass the data
$this->load->view("/tpl/template_base", $data);

in the view, the /tpl/template_base.php
Code:
<div class="main-content">
&lt;?php
// loads a view if the $main_content is passed
isset($main_content) ? $this->load->view($main_content) : "";
?&gt;
</div>

and you can do this for has many views as you want
just pass

Code:
$data['navigation'] = 'views/navigation';
$data['banners'] = 'views/banners';
$this->load->view('template_base', $data);

this way you can send multiple views to the template


site inside enclosing html - El Forum - 02-11-2011

[eluser]Unknown[/eluser]
Is it concidered bad practice to do this using hooks? so for example to make a pre_controller hook that displays something like "&lt;html&gt;&lt;div id='wrapper'>";
and a post_controler that displays "</div>&lt;/html&gt;"?

p.s. yes, I know there should also be head and body tags, this was just an example.