My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 30, 2008 by alex.aperez
Labels: Featured
Documentation  

#Temper (Kohana Template Parser Module) Documentation

Introduction

Just a brief introduction to the module and it's usage.

Syntax

Temper uses three types of delimiters, {}, {{}}, <prefix:tag></prefix:tag>

The first one indicates a variable string, second represents function calls and third type identyfies predefined tags.

Variables

Functions

Predefined Tags

Temper defines tags as objects, each tag should extend Temper_Tag class, but there are some exceptions where Tags extend another Tags. You can write your own tags, but there are some bundled with the module.

if-elseif-else

    <ko:if var="a" eq="a">a
    <ko:elseif var="a" eq="b" />b
    <ko:elseif var="a" neq="">set
    <ko:else />not set</ko:if>

for

    <ko:for var="x" start="1" end="10" increment="1">
        <ko:for var="y" start="1" end="10" increment="1">
	    <ko:print>$x * $y</ko:print>
        </ko:for>
    </ko:for>

foreach

    <ko:foreach var="tags" key="key" val="tag">
	<a href="{/search/=tag/}" title="{=tag}">{=tag}</a>
    </ko:foreach>

switch

    <ko:switch var="a">
        <ko:case val="a"><li>a</li></ko:case>
        <ko:case val="b"><li>b</li></ko:case>
    </ko:switch>

Comment by maartenvanvliet, Apr 03, 2008

I really should compliment you with this library. I have plans on using it but I really like the syntax. Two questions, is it possible to add your own callbacks in the {=variable|function} syntax? I like Django's templating where you can do {{ bio|truncatewords:30 }} for example - http://www.djangoproject.com/documentation/templates/#filters

Second question, I'm not sure if it's already there but is there a standard treatment of variables like: http://www.djangoproject.com/documentation/templates/#automatic-html-escaping

So you can escape your vars by default and explicitly disable it when you're sure it's not necessary.

Comment by alex.aperez, Apr 29, 2008

sorry for the delayed response, didn't notice about your comment,

for your first question, sure, you can use your own functions, but at this moment without params.

i'm not really sure about second, never tested anything like this, can you put some examples on how this can be a problem with current temper version?

Comment by gavinengel, Jan 07, 2009

A few questions...

#1 Would it be difficult to use this print syntax: Hello $u.first_name $u.las

Instead of: Hello {=u.first_name} {=u.last_name}

#2 Instead of: <ko:if var="a" eq="a"> Could I somehow use? (without ko:): <if var="a" eq="a">

the <if><else><elseif> tags aren't reserved for anything in XHTML, so why not?

#3 also, I haven't tried, but say I use a var as a boolean flag, does this syntax work?: <ko:if var="is_valid">

It is valid!
<ko:else>
It is invalid!
</ko:if>

-Gavin

Comment by gavinengel, Jan 07, 2009

By the way, you use: config::item(

Whereas Kohana is now using: Kohana::config(

Comment by write2howie, Feb 16, 2009

In Kohana v2.3 as well as updating config::item as mentioned above, the file suffix in the config file needs updating to remove the dot delimiter

$config'extension'? = 'tpl';

I think that the way Kohana::find_file has been changed.

Lost hours on that one!


Sign in to add a comment
Hosted by Google Code