NAME
PEF::Front::RenderTT - Template processing
DESCRIPTION
Template engine is implemented by Template::Alloy module using Template::Toolkit style. You can use all functions that provided by Template::Alloy module plus a few more.
SETTINGS
Template::Alloy module setup using "V2EQUALS => 0", this means that for string comparison you have to use "eq" operator and "==" for numerical.
PATH
Templates are located in cfg_template_dir($request, $lang) (See PEF::Front::Config), they are called like $template.html and are accessible by path /app$Template. Its file name is a lower-case converted from CamelCase form with suffix .html
. Like: /appIndex
-> index.html
, /appUserSettings
-> user_settings.html
.
This /app$Template
path is created automatically when you put your template in template directory.
CONTEXT
During template processing following context variables are pre-defined:
- ip
-
IP address of the client.
- lang
-
Short (ISO 639-1) language code. There's automatic language detection based on URL, HTTP headers and cookies and Geo IP. You can turn it off. It's written to 'lang' cookie.
- hostname
-
Hostname of current request.
- path
-
Current URI path.
- path_info
-
Initial URI path.
- template
-
Template name.
- scheme
-
URL scheme. One of: 'http', 'https'.
- src
-
Is equal to 'app'.
-
These are corresponding hashes. form contains parameters from query string, form data and extra parameters from URI path.
- session and request
-
They are objects and can be used from handlers or from template.
session
is loaded only if it was used for parameter value. - time, gmtime, localtime
-
These are additional fields for template processing.
time
is current UNIX-time,gmtime
- 9-element list with the time in GMT,localtime
- 9-element list with the time for the local time zone. Seeperldoc -f
for these functions.
ADDED FUNCTIONS
There're some additional functions defined.
model()
It can be used as virtual method for string or hash:
[% news = "get all news".model(limit => 3) %]
or
[% news = {method => "get all news", limit => 3}.model %]
This method calls internal model handler to get some data. Source template must be allowed.
config($key)
Returns config's parameter value.
[% config('www_static_captchas_path') %]
uri_unescape($uri)
Returns a string with each %XX sequence replaced with the actual byte (octet).
strftime($fmt, 9-elements array)
Convert date and time information to string. Returns the string.
See strftime
in POSIX.
gmtime($time), localtime($time)
Return 9-elements array. See corresponding perl functions.
response_content_type($ct)
Sets response Content-Type header.
request_get_header($h)
Returns request header
response_set_header($h => $v)
Sets response header.
response_set_cookie($c => $v)
Sets response cookie.
response_set_status($code)
Sets response status code.
session($key)
Returns session data.
Localization
m($msgid, @args)
Returns localized text for message $msgid. It supports parameterized messages like:
[% m('Hello $1', user.name) %]
$1
means first argument, $2
means second, etc.
mn($msgid, $num, @args)
This works like m($msgid, @args)
but supports singular/plural forms. $num
is used to select right form.
[% mn('You just deleted $1 unimportant files', number, number) %]
In this example first number
selects singular/plural form and second number
is argument.
ml($msgid, $lang, @args)
This is like m($msgid, @args)
but language is selectable.
mnl($msgid, $num, $lang, @args)
This is like mn($msgid, $num, @args)
but language is selectable.
Even if you use only one language it has some sense to use localization: it can help you to translate from "programmers" language to "usual user" language.
AUTHOR
This module was written and is maintained by Anton Petrusevich.
Copyright and License
Copyright (c) 2016 Anton Petrusevich. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.