|
#Temper (Kohana Template Parser Module) Documentation IntroductionJust a brief introduction to the module and it's usage. SyntaxTemper 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- {=variable} brings <?=$variable;?>
- {=variable|function} brings <?=function($variable);?>
- {foo.variable} represents an object or an array element
- {/path/to/} brings http://example.com/path/to/
- {/path/to/=variable/} brings http://example.com/path/to/<?=$variable;?>
Functions- {{echo({%foo})}} brings <?php echo($foo);?>
- {{class::method({%foo}, 'arg', 'arg')}} brings <?= call_user_function_array(array('class','method'), array('arg','arg'));?>
Predefined TagsTemper 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>
|
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.
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?
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">
<ko:else> </ko:if>-Gavin
By the way, you use: config::item(
Whereas Kohana is now using: Kohana::config(
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!