Reputation: 21
I'm using Kohana Framework and this is actually the first framework that I am using. I just wanted to know how to properly add templates in views. What I am doing right now is.
In controller.
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller_Template {
public $template = 'site';
public function action_index()
{
$this->template->header = View::factory('templates/header');
$this->template->header->title = 'Page name - Welcome';
$this->template->header->description = 'Blah blah blah.';
}
Now inside view I make a file called site.php (the view) and echo the variable $header on the top so it shows the contents of the page, and it's working fine but is it actually the right way to do it? I mean echoing out the header in every single view? I'm sure there must be a more complex or better way to do that. I have also heard that the use of Kohana Templete is discouraged.
Upvotes: 2
Views: 3131
Reputation: 1607
Have a look at Kostache It allows you to do simple things like
<li>{{kostachevariable}}</li>
You just create the view extending Kostache class and that's it. Once you do that you can just set variables using
$pagetitle="My Title"
$myview-bind('mypagetitle',$pagetitle)
In your template file you will only need
<head>
<title>{{mypagetitle}}</title>
It has tons of other nice features.
Upvotes: 0