Page 1 of 1

Header templating help

Posted: Thu Mar 10, 2011 7:33 pm
by brettski
Hi there, ok I'm stuck...

I need to show different headers for certain pages on my website, My template file below calls in all template parts with the 'layout' file being the file which includes a simple html header and menu. How would I go about this? Would I need to create and call on a seperate/second layout file eg. layout2 or can I determine which header shows on certain pages by adding some code to the layout file itself.

Any help greatly greatly appreciated.

Code: Select all

<?php

class Templating extends Model{
	function __constructor(){
	}


	function show($center = 'homepage', $right = 'login_box', $left ='left/search_panel', $template = 'layout'){
		$data = array(
			'right_bar' => $right,
			'left' => 'left/search_panel',
			'center' => $center,
			'left_logged'=>'left/user_panel'

		);
		if ($this->session->userdata('logged_in') == true){

			if ($this->session->userdata('admin')){
				#$data['right_bar'] = 'right_panel/admin_panel';
				$data['left_logged'] = 'right_panel/admin_panel';

			}else{
				#$data['right_bar'] = 'right_panel/user_panel';
				$data['left_logged'] = 'left/user_panel';
				//$data['left']      = 'left_panel/user_panel';
			}
		}else{
			#$data['right_bar'] = 'right_panel/login_box';
		}


		$this->load->vars($data);
		$this->load->view($template);
	}

	
	function show_non_live(){
		$data = array(
			'left' => 'left/search_panel',
			'center' => 'center/list_companies',
			'left_logged'=>'left/user_panel'
		);
		if ($this->session->userdata('logged_in') == true){
			if ($this->session->userdata('admin')){
				//$data['right_bar'] = 'right_panel/admin_panel';
				$data['left_logged'] = 'right_panel/admin_panel';
			}else{
				//$data['right_bar'] = 'right_panel/user_panel';
				$data['left_logged'] = 'left/user_panel';
			}
		}else{
			#$data['right_bar'] = 'right_panel/login_box';
		}
		$template = 'layout';
		$this->load->vars($data);
		$this->load->view($template);
	}
}

?>

Re: Header templating help

Posted: Fri Mar 11, 2011 1:59 am
by cpetercarter
Did you write this code yourself? If you didn't, the best person to ask is the author.

What do you mean by "header"? Do you mean:

- a message sent by the server to the browser with information about eg the sort of file which the server is about to send?
- the <head></head> section of the page html
- something which displays at the top of the webpage (eg a banner with the name of the website)

You could certainly achieve what you want by having a separate layout file for each layout you want, with code in the Templating class to determine which layout to call. I do not know whether the alternative - putting the logic in the layout file itself - will work, because you have told us nothing about the sort of file it is. Is it a php file? or a file written in a templating language? For either option, you need to consider how your programme will know which layout to call, and how the information necessary to make this choice can be made available to the script. If the information is in $_POST variables (eg if ($_POST['page'] == 1) do this (if $_POST['page'] == 2) do something else) then the task is relatively straightforward, since $_POST variables are 'global' ie they can be accessed from anywhere. But if the necessary information is in a different form, then you will need to find a way of passing it to the script which needs it.

Sorry this is only a very general reply, but you have not given us much to go on.