Welcome Guest, Not a member yet? Register   Sign In
nested views?
#1

[eluser]thomas86[/eluser]
Hello,

this is the 2nd day i work with CI and i have a question regarding to views. What is if i have a mainpage and want to display news or blogs or ...whatever... in the center of the page. So i need a main view for the mainpage design... banner, navigation, footer and so on ... but how can i include my blog view in the main view. The Blog view only contains of some div elemts.

cheers
Thomas
#2

[eluser]The Questioner[/eluser]
If you check the CI Wiki page, there is a section called "How do I embed views within views? Nested templates? Header, Main, Footer (Blocks) design? Partials? Page Fragments? Ruby on Rails style Yield functionality?". This will give you links to threads on how to achieve what you want.
#3

[eluser]thomas86[/eluser]
at that moment i find an interesting article for me ... http://codeigniter.com/wiki/Displaying_Multiple_Views/ ... but thanks a lot
#4

[eluser]mdvaldosta[/eluser]
What I do is very simple, and works quite well. I create a template view and put the design in there. I use $this->load->view($view) in the main content div of the design and use variables like $title, $description etc. to display things like the page title, meta description, H1, etc. on the page. From the controller I pass that info in the data array to the template, and the template uses it to build the page and call the view I want to load. CSS, etc are put in an assets folder outside of the application folder. If that sounds confusing, it looks like this:

Controller:
Code:
$data['title'] = 'Administration Dashboard';
$data['view'] = 'index';
$this->load->view('admin_template', $data);

Template (stripped down for this example):
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head profile="http://gmpg.org/xfn/11"&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
    &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
    &lt;link rel="stylesheet" href="&lt;?php echo base_url(); ?&gt;assets/site/css/style.css" type="text/css" /&gt;
&lt;/head&gt;

&lt;body&gt;
    
<h1>&lt;?php echo $title; ?&gt;</h1>
<div>
    &lt;?php $this->load->view($view); ?&gt;
</div>

&lt;/body&gt;
&lt;/html&gt;

And of course, the css and other things are located in an 'assets' folder in the root directory. The views are just normal views. You can, of course, break that template down into header/footer/sidebar/etc. if you wanted and just load it the same way you're loading the content view.

PS - I use CI 2.0 if that matters.
#5

[eluser]thomas86[/eluser]
Thank you, very helpfull.




Theme © iAndrew 2016 - Forum software by © MyBB