Description | manuals and libraries |
LedgerSMB::Template - Template support module for LedgerSMB
This module renders templates to an in-memory property.
This module does not handle the output/delivery of the rendered template to browser, file, e-mail etc. For that, see modules such as LedgerSMB::PSGI::Util and LedgerSMB::Legacy_Util.
Instantiates a new template. Accepts the following arguments:
A LedgerSMB::User object defining user preferences.
The template to be processed. This is the file that is the template to be processed. When 'path' equals 'DB', the file is retrieved from the database instead of from disk. Based on the specified format, an appropriate extension is appended to resolve to the correct template file.
The formatter to be used. Currently HTML, PS, PDF, TXT, CSV, ODS, XLS, XLSX are supported, through the plugins in LedgerSMB::Template::Plugin modules, subject to their dependencies being available.
A hash of format-specific options. See the appropriate LSMB::T::foo for details.
A hash of output-specific options, not used internally by LedgerSMB::Template. These options may be used by output/delivery code.
For example, if the output is sent as an HTTP response using LedgerSMB::PSGI::Util::template_to_psgi(), the output option filename
causes Content-Disposition
headers to be generated of the type attachment
(forcing file download).
The locale object to use for regular gettext lookups. Having this option adds the text function to the usable list for the templates. Has no effect on the gettext function.
The language for template selection.
Overrides the template directory.
The special value 'DB' enforces reading of the template from the current database. Resolving the template takes the 'language' and 'format' values into account.
Enables template debugging.
With the TT-based renderers, HTML, PS, PDF, TXT, and CSV, the portion of the template to get debugging messages is to be surrounded by <?lsmb DEBUG format 'foo' ?> statements. Example:
<tr><td colspan="<?lsmb columns.size ?>"></td></tr>
<tr class="listheading">
<?lsmb FOREACH column IN columns ?>
<?lsmb DEBUG format '$file line $line : [% $text %]' ?>
<th class="listtop"><?lsmb heading.$column ?></th>
<?lsmb DEBUG format '' ?>
<?lsmb END ?>
</tr>
Returns the LedgerSMB::Template object itself. Dies on error.
The rendered template result is available from the LedgerSMB::Template object's output
property, based on variables
and raw_variables
.
variables
are escaped using the specific mechanism to the output format. raw_variables
are passed without escaping or processing to the template processor.
Returns the name of the Template source, incorporating the specified extension as appropriate.
Returns a hash with the default arguments for the Template and the desired file extention
Preprocess for rendering. This is not an object method, it is a standalone subroutine.
The result of rendering the template.
The mimetype of the rendered template.
Not used internally by LedgerSMB::Template, but used as a way of passing options to output/delivery code, such as LedgerSMB::PSGI::Util::template_to_psgi().
Templates can make use of the following functions, installed by the template processor, when available for the current format.
This function looks up the translation of $string
in the language lexicon, interpolating the string's variable placeholders with the arguments provided in @args
. The resulting string will be escaped using the escape
function.
Note: This string looks up the exact string $string
, which makes it unsuited for translation of string values passed to the template through (escaped) string variable values.
These functions retrieve a file uploaded through System > Files. dbfile_path
returns a file name on the file system holding the content of the file in the database. dbfile_string
returns the content of the uploaded file in a string, whereas dbfile_base64
returns the content in a string, encoded using base64 encoding.
The file returned by dbfile_path
is guaranteed as long as a reference to the template is kept. There are no guarantees beyond the life of the template itself.
The template employs formats for a number of format-specific tasks:
In order to perform these actions, formats need to implement the following entry-points:
The template calls this function with one scalar value as its argument, repeatedly until all values to be passed to the template have been escaped.
The return value is the escaped value to substitute for $value
. The escaping mechanism is format specific.
The template calls this function with one scalar value as its argument, in order to reverse the transformation as applied by escape
.
The template driver calls this function just before the evaluation of the template. The $parent
is an instance of this class. The $variables
is a hashref containing the escaped variable values which will be passed to the template. $output
holds the output destination; either a string (containing a filename) or a scalar reference (for in-memory capturing of template output).
This function returns a tuple with the first value being the (temporary) output destination and the second a configuration hash with at least the following keys:
This extension, together with the base name specified by the caller of the renderer, is used to look up the format specific template.
This value indicates which binmode to use for the output being generated. Valid values are ':utf8'
, 1
or 0
.
The configuration hash can be used as a communication channel between setup
and postprocess
by adding keys starting with an underscore (_
).
After the Template Toolkit engine has been initialized based on the values returned by setup
, the driver calls this function, if a format provides it.
$config
corresponds with the second argument returned by setup
.
$template
is an instance of a Template Toolkit template processor - its value can be used to register plugins if such is required for the specific format.
After having evaluated the template, the driver calls this function. Its arguments are the instance of the driver $parent
(same as for setup
), $output
(the first item of the tuple returned by setup
) and the configuration hash $config
.
This function does not have a defined return value, but should return undef
for forward compatibility.
Returns the MIME content-type for the rendered template.
Copyright (C) 2007-2020 The LedgerSMB Core Team
This file is licensed under the GNU General Public License version 2, or at your option any later version. A copy of the license should have been included with your software.