PEF::Front::RenderTT - Template processing
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.
Template::Alloy module setup using "V2EQUALS => 0", this means that for string comparison you have to use "eq" operator and "==" for numerical.
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.
.html
/appIndex
index.html
/appUserSettings
user_settings.html
This /app$Template path is created automatically when you put your template in template directory.
/app$Template
During template processing following context variables are pre-defined:
IP address of the client.
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 of current request.
Current URI path.
Initial URI path.
Template name.
URL scheme. One of: 'http', 'https'.
Is equal to 'app'.
These are corresponding hashes. form contains parameters from query string, form data and extra parameters from URI path.
They are objects and can be used from handlers or from template.
session is loaded only if it was used for parameter value.
session
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. See perldoc -f for these functions.
time
gmtime
localtime
perldoc -f
There're some additional functions defined.
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.
Returns config's parameter value.
[% config('www_static_captchas_path') %]
Returns a string with each %XX sequence replaced with the actual byte (octet).
Convert date and time information to string. Returns the string.
See strftime in POSIX.
strftime
Return 9-elements array. See corresponding perl functions.
Sets response Content-Type header.
Returns request header
Sets response header.
Sets response cookie.
Sets response status code.
Returns session data.
Returns localized text for message $msgid. It supports parameterized messages like:
[% m('Hello $1', user.name) %]
$1 means first argument, $2 means second, etc.
$1
$2
This works like m($msgid, @args) but supports singular/plural forms. $num is used to select right form.
m($msgid, @args)
$num
[% mn('You just deleted $1 unimportant files', number, number) %]
In this example first number selects singular/plural form and second number is argument.
number
This is like m($msgid, @args) but language is selectable.
This is like mn($msgid, $num, @args) but language is selectable.
mn($msgid, $num, @args)
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.
This module was written and is maintained by Anton Petrusevich.
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.
To install PEF::Front, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PEF::Front
CPAN shell
perl -MCPAN -e shell install PEF::Front
For more information on module installation, please visit the detailed CPAN module installation guide.