Template-Alloy
view release on metacpan or search on metacpan
But the following:
[% CONFIG INTERPOLATE => 1, SHOW_UNDEFINED_INTERP => 1 %]
[% SET foo = 1 %][% SET bar %]
($foo)($bar) ($!foo)($!bar)
Would print:
(1)($bar) (1)()
Note that you can use an exclamation point directly after the dollar
to make the variable silent. This is similar to how Velocity works.
START_TAG
Set a string or regular expression to use as the opening delimiter
for TT. Default is "[%". You should be sure that the tag does not
include grouping parens or INTERPOLATE will not function properly.
STASH
Template::Alloy manages its own stash of variables. You can pass a
Template::Stash or Template::Stash::XS object, but Template::Alloy
will copy all of values out of the object into its own stash.
Template::Alloy won't use any of the methods of the passed STASH
object. The STASH option is only available when using the process
method.
STAT_TTL
Defaults to $STAT_TTL which defaults to 1. Represents time-to-live
seconds until a cached in memory document is compared to the file
system for modifications. Setting this number higher will allow for
fewer file system accesses. Setting it to a negative number will
allow for the file system to be checked every hit.
STREAM
Defaults to false. If set to true, generated template content will
be printed to the currently selected filehandle (default is STDOUT)
as soon as it is ready - there will be no buffering of the output.
The Stream role uses the Play role's directives (non-compiled_perl).
All directives and configuration work, except for the following
exceptions:
CLEAR directive
Because the output is not buffered - the CLEAR directive would
have no effect. The CLEAR directive will throw an error when
STREAM is on.
TRIM configuration
Because the output is not buffered - trim operations cannot be
played on the output buffers.
WRAPPER configuration/directive
The WRAPPER configuration and directive items effectively turn
off STREAM since the WRAPPERS are generated in reverse order and
because the content is inserted into the middle of the WRAPPERS.
WRAPPERS will still work, they just won't stream.
VARIOUS errors
Because the template is streaming, items that cause errors my
result in partially printed pages - since the error would occur
part way through the print.
All output is printed directly to the currently selected filehandle
(defaults to STDOUT) via the CORE::print function. Any output
parameter passed to process or process_simple will be ignored.
If you would like the output to go to another handle, you will need
to select that handle, process the template, and re-select STDOUT.
STRICT
Defaults to false. If set to true, any undefined variable that is
encountered will cause the processing of the template to abort. This
can be caught with a TRY block. This can be useful for making sure
that the template only attempts to use variables that were correctly
initialized similar in spirit to Perl's "use strict."
When this occurs the strict_throw method is called.
See the STRICT_THROW configuration for additional options.
Similar functionality could be implemented using UNDEFINED_ANY.
The STRICT configuration item can be passed to new or it may also be
set during runtime using the CONFIG directive. Once set though it
cannot be disabled for the duration of the current template and sub
components. For example you could call [% CONFIG STRICT => 1 %] in
header.tt and strict mode would be enabled for the header.tt and any
sub templates processed by header.tt.
STRICT_THROW (not in TT)
Default undef. Can be set to a subroutine which will be called when
STRICT is set and an undefined variable is processed. It will be
passed the error type, error message, and a hashref of template
information containing the current component being processed, the
current outer template being processed, the identity reference for
the variable, and the stringified name of the identity. This
override can be used for filtering allowable elements.
my $ta = Template::Alloy->new({
STRICT => 1,
STRICT_THROW => sub {
my ($ta, $err_type, $msg, $args) = @_;
return if $args->{'component'} eq 'header.tt'
&& $args->{'template'} eq 'main.html'
&& $args->{'name'} eq 'foo.bar(1)'; # stringified identity name
$ta->throw($err_type, $msg); # all other undefined variables die
},
});
SYNTAX (not in TT)
Defaults to "cet". Indicates the syntax that will be used for
parsing included templates or eval'ed strings. You can use the
CONFIG directive to change the SYNTAX on the fly (it will not affect
the syntax of the document currently being parsed).
The syntax may be passed in upper or lower case.
( run in 0.908 second using v1.01-cache-2.11-cpan-5a3173703d6 )