Question

I can't seem to set the $template variable dynamically of a site built on Kohana.

If I extend the Template_Controller class, I can set the template name like this:

public $template = 'template_file_name';

But I can't set it dynamically like:

public $template = $this->setTemplate();

or

switch($var):
    default:
       public $template = 'filename';
       break;
endswitch;

Changing the $template variable using $this->template in the constructor breaks the Template_Controller somehow:

Fatal error: Call to a member function render() on a non-object

I need to set the template filename based on a variable set in the constructor, or perhaps pulled from an external library.

Any ideas how to make this possible?

Was it helpful?

Solution

this link may have the answer:

http://stii.co.za/php/overriding-default-template-in-kohana-php/

just run your template constructor as this:

public function __construct()
    {
        $this->template = 'foobar';
        parent::__construct();
    }

OTHER TIPS

I do it like this:

public function action_myaction()
{
    // template
    $this->template = "template/overlay";
    parent::before();

    // display
    $this->template->title = 'My Action';
    $this->template->content = View::factory('myaction')
}

More information here: http://www.workinprogress.ca/kohana32/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top