CodeIgniter Forums
Styles not fully applying when loading nested view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Styles not fully applying when loading nested view (/thread-40933.html)



Styles not fully applying when loading nested view - El Forum - 04-22-2011

[eluser]zulubanslee[/eluser]
I want to modularize a little, so my menu section is one view and my sidebar is another and the footer another. I wanted to do this:

Here is my controller code:
Code:
$data['header'] = $this->load->view('header');
$data['sidebar']= $this->load->view('sidebar');
$data['footer'] = $this->load->view('footer');
$this->load->view('main_view');

Then in the view I have
Code:
<!--html-->
<?php echo $header;?>
<!--more  html-->
<?php echo $sidebar;?>
<!--more html-->
<?php echo $footer;?>

It prints, but see this:

http://i.imgur.com/W5sqo.jpg

I left out the sidebar and footer because it's more of a mess.

With the code in one file it's fine.


Styles not fully applying when loading nested view - El Forum - 04-22-2011

[eluser]InsiteFX[/eluser]
Your problem is that you are not passing the $data array to the view!
There is 2 different ways of doing this...
Code:
// First
$data['header'] = $this->load->view('header');
$data['sidebar']= $this->load->view('sidebar');
$data['footer'] = $this->load->view('footer');

$this->load->view('main_view', $data);

Code:
// Second - Which makes $data global.
$data['header'] = $this->load->view('header');
$data['sidebar']= $this->load->view('sidebar');
$data['footer'] = $this->load->view('footer');

$this->load->vars($data);

$this->load->view('main_view');

InsiteFX


Styles not fully applying when loading nested view - El Forum - 04-22-2011

[eluser]zulubanslee[/eluser]
Eh I tried that and it looks the same. If I forgot to pass the $data variable, how was it the header was passed in the first place, incorrectly positioned or otherwise?


Styles not fully applying when loading nested view - El Forum - 04-22-2011

[eluser]InsiteFX[/eluser]
If your talking about your header it's because your div is not centering it!

Code:
.header { width: 100%; margin: 0 auto; }

// html
<div class="header">
    // load your header here.
</div>

InsiteFX


Styles not fully applying when loading nested view - El Forum - 04-22-2011

[eluser]zulubanslee[/eluser]
Very good. I applied:

margin: auto;

and that did the trick. I'm a bit curious as to why it aligned ok when it was in the original file, but as long as it works, who cares right?

thanks guys!


Styles not fully applying when loading nested view - El Forum - 04-22-2011

[eluser]InsiteFX[/eluser]
Your very Welcome!

What I showed you will work for centering any divs.

InsiteFX