[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
[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?
[eluser]KeyStroke[/eluser]
is this basically the modification? or is there more to it?
[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>
</body>
</html>
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:
<!-- INCLUDE overall_header.tpl -->
<div>
Some dynamic content:
{Content}
</div>
<!-- INCLUDE overall_footer.tpl -->
[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:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="<?php echo $this->config->item('meta_desc'); ?>" />
<meta name="keywords" content="<?php echo $this->config->item('meta_key_words'); ?>" />
<meta name="author" content="<?php echo $this->config->item('game_owner'); ?>" />
<link rel="shortcut icon" href="<?php echo $this->config->item('favicon'); ?>" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/960.css" media="screen" />
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/css/pri.css" media="screen" />
<title><?php echo $title.' | '.$this->config->item('game_name'); ?></title>
</head>
<body>
<div class="container_12">
<div class="grid_12">
<h3><?php echo $this->config->item('game_name'); ?></h3>
</div>
<div class="grid_2">
<?php $this->load->view('menus/'.$menu); ?>
</div>
<div class="grid_10">
<?php $this->load->view($content); ?>
</div>
<div class="grid_12">
<div class="left">
<p class="italic small"><?php echo $this->config->item('game_name'); ?> © All Rights Reserved Worldwide <?php echo date('Y', time()); ?></p>
</div>
<div class="right">
<p><img src="<?php echo base_url(); ?>assets/imgs/time.png" alt="Time: " title="Time" /> <?php echo date('l, F jS, g:ia e', time()); ?></p>
</div>
</div>
</div>
</body>
</html>