[eluser]GregX999[/eluser]
Sorry for the strange subject...
I'm using a pretty basic, home-brewed template system. Basically, my controller methods call a "render" function that calls a layout view, then the layout view then calls the "content view". I'd like to know if there's a way for a variable set in the content view to be used by the layout view. Perhaps it's more clear with examples:
A method from a controller:
Code:
function about()
{
$data['page_title'] = 'About Our Wonderful Stuff';
$data['extra_css'][] = 'about';
$this->view->render($data, 'about');
}
Note: In the last line, 'about' is the name of the view to load.
The render function (in a custom library, view.php):
Code:
function render($data, $view, $layout='main')
{
$data['view'] = $view;
$data['CI'] =& $this->CI; // Passed through so that the layout file can call "load->view" in order to load the view.
$data['data'] = $data; // Add $data to itself so that $data will be available in the view (after load->view is called a second time)
$this->CI->load->view("layouts/{$layout}", $data);
}
Note: I'm adding $view to the $data array.
The "main" layout (as opposed to the "popup" layout or any other layout that the site may use):
Code:
<html>
<head>
<title><?= SITE_NAME ?> : <?= $page_title ?></title>
<link type="text/css" rel="stylesheet" href="/css/reset.css" />
<link type="text/css" rel="stylesheet" href="/css/main.css" />
<? if(isset($extra_css)): ?>
<? foreach($extra_css as $css) :?><link type="text/css" rel="stylesheet" href="/css/<?= $css ?>.css" /><? endforeach; ?>
<? endif; ?>
</head>
<body>
<div id="main_header" class="clearfix">
Site header goes here
</div>
<div id="main_content" class="clearfix">
<?= $CI->load->view($view, $data); ?>
</div>
<div id="main_footer" class="clearfix">
Site footer goes here
</div>
</body>
</html>
Two things to note: The page_title and extra_css are variables. The "main_content" div is being "loaded" as it's a separate view.
And the "about" view:
Code:
<div id="toffees">
Blah, blah blah...
</div>
So... my main question: How can I move page_title and extra_css from the "about" method in the controller into the "about" view? So that my "about" view would look like this:
Code:
<? $data['page_title'] = 'About Our Wonderful Stuff'; ?>
<? $data['extra_css'][] = 'about'; ?>
<div id="toffees">
Blah, blah blah...
</div>
Is it possible?
Greg