Multiple templates, loading default variables for main template?

#1
[eluser]fancms[/eluser]
Currently I have it set up like so:

- template is the main template that wraps around the content. it contains a variable to echo the content passed by the controller
- in the controller I have it set up so that
$data = all the template variables I need to load for that controller
Code:
$template['content'] = $this->parser->parse('controllertemplatename', $data, true); #calls the parser

- finally, the call to output the whole page:
Code:
$this->parser->parse('maintemplatename', $template);

My problem is that the main template has tags (ie {lang_something}), and those tags are of course not going to get output properly because the $template variable doesn't hold the array for it. I could copy/paste the array with the needed variables but then I'd need to do it for every controller which would make upgrading that menu a nightmare.

Do I need to create a controller for the main template? Is there a way to load the array of variables without copy/pasting it over and over? Am I overlooking something completely obvious? (Wouldn't be the first time Wink)

#2
[eluser]Jatinder Thind[/eluser]
I use views to accomplish something similar to what you want to do. Take a look at the code below:

Code:
//This data will be passed to controllertemplatename view
$inner = array();
$inner['some_data'] = $some_data;

//This data will be passed to maintemplatename view
$page = array();
$page['additional_data'] = "Some additional data";
$page['content'] = $this->load->view('controllertemplatename', $inner, TRUE);

$this->load->view('maintemplatename', $page);

This should be pretty self explanatory. Let me know if you need detailed explanation.

#3
[eluser]Unknown[/eluser]
Hi Jatinder...i was working like you with your '$inner method'...i was read it before in other post and it works well...but, imagine that you have this
Code:
$data_principal['base']=$this->config->item('base_url');  //just some paths in my config
...more variables...

$data_principal['base']=$this->config->item('base_url')   // the same paths
...more variables...

$data_principal['content']=$this->load->view('content',$data_paths,TRUE);   //here
$this->load->view('index',$data_principal);

how i can send the content of $data_principal to 'content' view and 'index' view at the same time with a single array??

thanks a lot

#4
[eluser]InsiteFX[/eluser]
You can also do it like this:

Code:
function index()
    {
        $data['posts']            = $this->posts_m->get_posts(10);
        $data['categories']    = $this->category_m->get_categories();
        $data['title']            = "Welcome";
        $data['main']            = 'home';
        
        $this->load->vars($data);
        $this->load->view('template');
    }

Enjoy
InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.