You should be able to do it like this:
welcome.php
view:
<?php View::set_global('title', 'Some title'); ?>
<h1>Hello, world!</h1>
Controller_Welcome
class:
class Controller_Welcome extends Controller_Base {
public function action_index () {
$this->template->content = View::factory('welcome')->render();
}
}
Note the call to render()
- it is very important in order for this to work! In the normal execution flow, the base
view will be evaluated first, followed by the inside. In order for the call to set_global
to be made before the base is rendered, you must explicitly render the inside first.
Aside: If you are doing any significant templating stuff, you really should consider using Kostache with proper "ViewModel" classes, which are a much more elegant way to solve this problem.