Welcome Guest, Not a member yet? Register   Sign In
Styles not fully applying when loading nested view
#1

[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.
#2

[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
#3

[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?
#4

[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
#5

[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!
#6

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

What I showed you will work for centering any divs.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB