Welcome Guest, Not a member yet? Register   Sign In
How to insert view into another view?
#11

(This post was last modified: 01-10-2016, 07:40 AM by Wouter60.)

I've solved this by creating my own template.
E.g., in the folder views/template I have a file named "template.php".  Contents of this file:
PHP Code:
$this->load->view('template/header');
$this->load->view($main_content);
$this->load->view('template/footer'); 

In my controller, I load the 'news' page like this:
PHP Code:
$data['main_content'] = 'news';
$data['records'] = ...; // (sql-statement to load the news records)
$this->load->view('template/template',$data); 

Important! The variables that are passed to the template through the $data array, are available in all views that are loaded into the template.
Reply
#12

(01-10-2016, 07:22 AM)Wouter60 Wrote: I've solved this by creating my own template.
E.g., in the folder views/template I have a file named "template.php".  Contents of this file:
PHP Code:
$this->load->view('template/header');
$this->load->view($main_content);
$this->load->view('template/footer'); 

In my controller, I load the 'news' page like this:
PHP Code:
$data['main_content'] = 'news';
$data['records'] = ...; // (sql-statement to load the news records)
$this->load->view('template/template',$data); 

Important! The variables that are passed to the template through the $data array, are available in all views that are loaded into the template.

PHP Code:
<?php

$view_data
['some_var'] = 'Foo';

$data['content'] = $this->load->view('nested_view'$view_dataTRUE);

$this->load->library('main_view'$data); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB