Welcome Guest, Not a member yet? Register   Sign In
The idea of templates for header/footer
#1

[eluser]Unknown[/eluser]
Hi,

While I was continuing with my tutorials and other stuff I came across an idea to create a template view that would load a couple of other views like header, footer and the main content. I like the idea as it would help to include my navigation menu on most of the pages without the need to load it explicitly in every place. The code of the view in the tutorial is something like that:

Quote:<?php $this->load->view('templates/header'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('templates/footer'); ?>

Now obviously when loading this view (let's call it template) I need to call $this->load->view('template', $data) and before that I need to pass the name of the main content view to $data, like for example $data['main_content'] = 'someview'.

This is more or less where it ends in the tutorial as for the view part. Now what I need to do is obviously pass some data to the main content view. If I understand well, in order to do that I would have to pass not only the name of the view that needs to be displayed in main_content but also its data. Now I have:

$data['main_content'] = 'someview';
$data['main_content_data'] = $someotherdata

and I need to modify the original view template.php to something like:

Quote:<?php $this->load->view('templates/header'); ?>
<?php $this->load->view($main_content, $main_content_data); ?>
<?php $this->load->view('templates/footer'); ?>

I guess that building an application that would have more or less constant menus and other stuff in place on every screen and just main content changing is a quite common task. That's why I would want to ask if the way provided above is the right way to do it or there are maybe other ideas on how to handle it?

Best regards,
Kuba


Messages In This Thread
The idea of templates for header/footer - by El Forum - 10-20-2013, 01:18 AM
The idea of templates for header/footer - by El Forum - 10-20-2013, 02:46 AM
The idea of templates for header/footer - by El Forum - 10-20-2013, 02:58 AM
The idea of templates for header/footer - by El Forum - 10-28-2013, 05:34 AM
The idea of templates for header/footer - by El Forum - 10-28-2013, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB