Welcome Guest, Not a member yet? Register   Sign In
How do you implement master templates that are used across the site?
#1

[eluser]KeyStroke[/eluser]
Hi,

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
#2

[eluser]Mischievous[/eluser]
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
Code:
$this->template->write_view('content', 'view_file');
$this->template->render();

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?
#3

[eluser]KeyStroke[/eluser]
is this basically the modification? or is there more to it?
#4

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

PHP:
Code:
$this->load->library('parser');

$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);

TPL:
Code:
<html>
<head>
</head>
<body>

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

&lt;/body&gt;
&lt;/html&gt;

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

PHP:
Code:
$this->load->library('parser');

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

TPL:
Code:
&lt;!-- INCLUDE overall_header.tpl --&gt;

<div>
Some dynamic content:
{Content}
</div>
&lt;!-- INCLUDE overall_footer.tpl --&gt;
#5

[eluser]Karlos23[/eluser]
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.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
    &lt;head&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;
    &lt;/head&gt;
    &lt;body&gt;
        <div class="container_12">
            <div class="grid_12">
                <h3>&lt;?php echo $this->config->item('game_name'); ?&gt;</h3>
            </div>
            <div class="grid_2">
                &lt;?php $this->load->view('menus/'.$menu); ?&gt;
            </div>
            <div class="grid_10">
                &lt;?php $this->load->view($content); ?&gt;
            </div>
            <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>
                <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>
                </div>
            </div>
        </div>
    &lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB