• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you implement master templates that are used across the site?


I'm basically trying to have a master template that I could always output content to (preferably automatically without a call) across the site.

I know some will suggest outputting every page section in its own $this->load->view() call in every method, but that's an incredibly ugly solution.

There's another way which consists of playing around with hooks to automatically output the master template, but it's a bit hackish in my opinion.

I've also found the Template library (http://www.williamsconcepts.com/ci/codei...index.html), which is so far my best option, but it's a bit complex and I'd rather use something simpler.

So, my question is, what do/would you use in such case where you need a master template?

Appreciate your help

I'm currently using a modified version of the Template Library you listed that i've modified to work with modular separation and it works amazingly! Its really really not complex at all!

Simply call
$this->template->write_view('content', 'view_file');

then first parameter is a the region you specify in the template_config file? and the second parameter is the view file to load into the region?

the config_file is a simple array?

is this basically the modification? or is there more to it?

If you use COMPER Template Parser (http://ellislab.com/forums/viewthread/153269/),
It's so simple:


$data = array
"header" => $this->parser->parse('header', $data_header),
"content" => $this->parser->parse('content', $data_content),
"footer" => $this->parser->parse('footer', $data_footer),

"color" => "green"
//another pseudo-variables ...

$this->parser->parse('master_template', $data);


  <div style='color: {green}'>{body}</div>


OR you can use "INCLUDE" in every template (yes it's not longer master template):


$this->parser->parse('template_file', array('Content' => 'Hello world!'));

&lt;!-- INCLUDE overall_header.tpl --&gt;

Some dynamic content:
&lt;!-- INCLUDE overall_footer.tpl --&gt;

Well I have a public var in my controller $data and each new controller contains it. It has a title, menu and content part to it what allows me to leave the template and just create other views leaving the master template alone.

&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?&gt;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
&lt;html &gt;
        &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/&gt;
        &lt;meta name="description" content="&lt;?php echo $this-&gt;config->item('meta_desc'); ?&gt;" />
        &lt;meta name="keywords" content="&lt;?php echo $this-&gt;config->item('meta_key_words'); ?&gt;" />
        &lt;meta name="author" content="&lt;?php echo $this-&gt;config->item('game_owner'); ?&gt;" />
        &lt;link rel="shortcut icon" href="&lt;?php echo $this-&gt;config->item('favicon'); ?&gt;" type="image/x-icon" />
        &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url(); ?&gt;assets/css/960.css" media="screen" /&gt;
        &lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url(); ?&gt;assets/css/pri.css" media="screen" /&gt;
        &lt;title&gt;&lt;?php echo $title.' | '.$this->config->item('game_name'); ?&gt;&lt;/title&gt;
        <div class="container_12">
            <div class="grid_12">
                <h3>&lt;?php echo $this->config->item('game_name'); ?&gt;</h3>
            <div class="grid_2">
                &lt;?php $this->load->view('menus/'.$menu); ?&gt;
            <div class="grid_10">
                &lt;?php $this->load->view($content); ?&gt;
            <div class="grid_12">
                <div class="left">
                    <p class="italic small">&lt;?php echo $this->config->item('game_name'); ?&gt; &copy; All Rights Reserved Worldwide &lt;?php echo date('Y', time()); ?&gt;</p>
                <div class="right">
                    <p><img src="&lt;?php echo base_url(); ?&gt;assets/imgs/time.png" alt="Time: " title="Time" /> &lt;?php echo date('l, F jS, g:ia e', time()); ?&gt;</p>

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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