CodeIgniter Forums
Loading a div in view. - 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: Loading a div in view. (/showthread.php?tid=15697)



Loading a div in view. - El Forum - 02-12-2009

[eluser]Unknown[/eluser]
while loading a view is it possible to load only a small part of a page.
Say i have a template page that contains 5 div's and i just want to load a single div(id=xyz).

In my controller i like to do something like this

public function index()
{
$this->load->view(<div id=xyz>);
}


Loading a div in view. - El Forum - 02-12-2009

[eluser]umefarooq[/eluser]
hi peace you have to do some thing like this.

controller
Code:
public function index()
  {
       $data['div1'] = '<div id="xyz">';
        $data['div2'] = '<div id="xyz">';
        $data['div3'] = '<div id="xyz">';
      $this->load->view('your_view_name',$data);
  }

view
Code:
&lt;html&gt;
&lt;body&gt;
&lt;? echo $div1?&gt;
&lt;? echo $div2?&gt;
&lt;? echo $div3?&gt;
&lt;/body&gt;
</htm>

its will work fine. you have to pass array of variables to view. check user guide also.


Loading a div in view. - El Forum - 02-12-2009

[eluser]Colin Williams[/eluser]
Or, fetch a smaller view and send it to the main one

Code:
$data['part'] = $this->load->view('part', '', TRUE);
// Use TRUE to capture result and not render it

$this->load->view('page', $data);
// There is now a $part var in the page.php view the holds the rendered contents of the part.php view