Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Start Using Kostache?

I just asked a question ( Templates In Kohana 3.1 ) about templates and now I know that I should use Kostache. It's a module for the Mustache template language.

Anyway, I just enabled Kostache module for my Kohana 3.1 and all works. It's installed correctly! What to do next? How to use it?

Where should I put my views now? What my controller should extend? How to assign variable? How to make header, footer etc. for views?

Maybe there are step to step guide for it? This and this won't help me a lot...

like image 687
daGrevis Avatar asked Jun 05 '11 20:06

daGrevis


People also ask

How do you get used to a mustache?

The easiest way is to “grow a bit of a beard first,” he says. “Once you get to your desired length, shape your beard down shorter [than your mustache].” You can do this gradually, each time cutting your beard closer and leaving the mustache alone, so you can see the shape and get used to the look.

When should you start using a mustache wax?

Getting StartedWhen you start growing facial hair it's a good rule of thumb to commit to letting it grow naturally for 1 to 3 months. This is so you can have a good idea of how your facial hair is going to grow in, and have an idea of the shape of your natural beard and moustache.

When should I start training my mustache?

Either way, you want at least six weeks of growth before you ever reach for the scissors. Two months is about the time frame it takes for a mustache to truly fill out and for the hairs growing near the nose to become long enough to reach the upper lip.


3 Answers

Where should I put my views now?

View classes contain logic for your templates and by convention should be stored in classes/view/{template name}.php

Templates contain your HTML and should be stored in the templates directory in the root of your module, e.g. templates/login.mustache

By default kostache will try and work out the location of the template based on your view class' name.

If your view class is called View_Admin_Login then kostache will look for templates/admin/login.mustache

What my controller should extend?

You do not need to extend any special controllers, the normal Controller will work fine as a base.

How to assign variable

Controller:

$view = new View_Admin_Login;

$view->message = 'Hello';
$this->response->body($view->render());

Template:

{{message}}

Of course, any methods or variables you declare in your view class will also be available in the template. If there is a class variable and method with the same name then the method will always take precedence over the variable.

How to make header, footer etc. for views

It will help if you read the kostache guide. The idea is that your views extend Kostache_Layout, see also the layout template

like image 98
Matt Avatar answered Oct 02 '22 23:10

Matt


There's lots of demos and examples in both of the repositories that you said won't help you.

like image 20
zombor Avatar answered Oct 02 '22 22:10

zombor


Try this...

//application/classes/controller:

class Controller_Test extends Controller {

 public function action_index()
 {
    $view = new View_Home;
    $this->response->body($view->render());
 }

}

//application/classes/view/Home.php:

class View_Home {
    public $name = "Chris";
    public $value = 10000;

    public function taxed_value() {
        return $this->value - ($this->value * 0.4);
    }

    public $in_ca = true;
    protected $_layout = 'home';
}

//application/templates/home.mustache:

Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
{{/in_ca}}
like image 29
Harshala Avatar answered Oct 02 '22 23:10

Harshala