.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Text::Xslate::Syntax::TTerse 3pm" .TH Text::Xslate::Syntax::TTerse 3pm "2018-11-02" "perl v5.28.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Text::Xslate::Syntax::TTerse \- An alternative syntax compatible with Template Toolkit 2 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& use Text::Xslate; \& my $tx = Text::Xslate\->new( \& syntax => \*(AqTTerse\*(Aq, \& ); \& \& print $tx\->render_string( \& \*(AqHello, [% dialect %] world!\*(Aq, \& { dialect => \*(AqTTerse\*(Aq } \& ); \& \& # PRE_PROCESS/POST_PROCESS \& $tx = Text::Xslate\->new( \& syntax => \*(AqTTerse\*(Aq, \& header => [\*(Aqheader.tt\*(Aq], \& footer => [\*(Aqfooter.tt\*(Aq], \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" TTerse is a subset of the Template-Toolkit 2 (and partially 3) syntax, using \f(CW\*(C`[% ... %]\*(C'\fR tags and \f(CW\*(C`%% ...\*(C'\fR line code. .PP Note that TTerse itself has few methods and filters while Template-Toolkit 2 has a lot. See \f(CW\*(C`Text::Xslate::Bridge::*\*(C'\fR modules on \s-1CPAN\s0 which provide extra methods and filters if you want to use those features. .PP (\s-1TODO: I\s0 should concentrate on the difference between Template-Toolkit 2 and TTerse) .SH "SYNTAX" .IX Header "SYNTAX" This supports a Template-Toolkit compatible syntax, although the details might be different. .PP Note that lower-cased keywords, which are inspired in Template-Toolkit 3, are also allowed. .SS "Variable access" .IX Subsection "Variable access" Scalar access: .PP .Vb 3 \& [% var %] \& [% $var %] \& [% GET var # \*(AqGET\*(Aq is optional %] .Ve .PP Field access: .PP .Vb 5 \& [% var.0 %] \& [% var.field %] \& [% var.accessor %] \& [% var.$field ]% \& [% var[$field] # TTerse specific %] .Ve .PP Variables may be \s-1HASH\s0 references, \s-1ARRAY\s0 references, or objects. .PP If \fI\f(CI$var\fI\fR is an object instance, you can call its methods. .PP .Vb 4 \& [% $var.method() %] \& [% $var.method(1, 2, 3) %] \& [% $var.method(foo => [1, 2, 3]) %] \& [% $var.method({ foo => \*(Aqbar\*(Aq }) %] .Ve .SS "Expressions" .IX Subsection "Expressions" Almost the same as Text::Xslate::Syntax::Kolon, but \f(CW\*(C`infix:<_>\*(C'\fR for concatenation is supported for compatibility. .SS "Loops" .IX Subsection "Loops" .Vb 3 \& [% FOREACH item IN arrayref %] \& * [% item %] \& [% END %] .Ve .PP Loop iterators are partially supported. .PP .Vb 10 \& [% FOREACH item IN arrayref %] \& [%\- IF loop.is_first \-%] \& \& [%\- END \-%] \& * [% loop.index %] # 0 origin \& * [% loop.count # loop.index + 1 %] \& * [% loop.body # alias to arrayref %] \& * [% loop.size # loop.body.size %] \& * [% loop.max_index # loop.size \- 1 %] \& * [% loop.peek_next # loop.body[ loop.index + 1 ] \& * [% loop.peek_prev # loop.body[ loop.index \- 1 ] \& [%\- IF loop.is_last \-%] \& \& [%\- END \-%] \& [% END %] .Ve .PP Unlike Template-Toolkit, \f(CW\*(C`FOREACH\*(C'\fR doesn't accept a \s-1HASH\s0 reference, so you must convert \s-1HASH\s0 references to \s-1ARRAY\s0 references by \f(CW\*(C`keys()\*(C'\fR, \f(CW\*(C`values()\*(C'\fR, or \f(CW\*(C`kv()\*(C'\fR methods. .PP Template-Toolkit compatible names are also supported, but the use of them is discouraged because they are not easy to understand: .PP .Vb 5 \& loop.max # for loop.max_index \& loop.next # for loop.peek_next \& loop.prev # for loop.peek_prev \& loop.first # for loop.is_first \& loop.last # for loop.is_last .Ve .PP Loop control statements, namely \f(CW\*(C`NEXT\*(C'\fR and \f(CW\*(C`LAST\*(C'\fR, are also supported in both \f(CW\*(C`FOR\*(C'\fR and \f(CW\*(C`WHILE\*(C'\fR loops. .PP .Vb 4 \& [% FOR item IN data \-%] \& [% LAST IF item == 42 \-%] \& ... \& [% END \-%] .Ve .SS "Conditional statements" .IX Subsection "Conditional statements" .Vb 7 \& [% IF logical_expression %] \& Case 1 \& [% ELSIF logical_expression %] \& Case 2 \& [% ELSE %] \& Case 3 \& [% END %] \& \& [% UNLESS logical_expression %] \& Case 1 \& [% ELSE %] \& Case 2 \& [% END %] \& \& [% SWITCH expression %] \& [% CASE case1 %] \& Case 1 \& [% CASE case2 %] \& Case 2 \& [% CASE DEFAULT %] \& Case 3 \& [% END %] .Ve .SS "Functions and filters" .IX Subsection "Functions and filters" .Vb 2 \& [% var | f %] \& [% f(var) %] .Ve .SS "Template inclusion" .IX Subsection "Template inclusion" The \f(CW\*(C`INCLUDE\*(C'\fR statement is supported. .PP .Vb 2 \& [% INCLUDE "file.tt" %] \& [% INCLUDE $var %] .Ve .PP \&\f(CW\*(C`WITH variables\*(C'\fR syntax is also supported, although the \f(CW\*(C`WITH\*(C'\fR keyword is optional in Template-Toolkit: .PP .Vb 5 \& [% INCLUDE "file.tt" WITH foo = 42, bar = 3.14 %] \& [% INCLUDE "file.tt" WITH \& foo = 42 \& bar = 3.14 \& %] .Ve .PP The \f(CW\*(C`WRAPPER\*(C'\fR statement is also supported. The argument of \f(CW\*(C`WRAPPER\*(C'\fR, however, must be string literals, because templates will be statically linked while compiling. .PP .Vb 3 \& [% WRAPPER "file.tt" %] \& Hello, world! \& [% END %] \& \& %%# with variable \& [% WRAPPER "file.tt" WITH title = "Foo!" %] \& Hello, world! \& [% END %] .Ve .PP The content will be set into \f(CW\*(C`content\*(C'\fR, but you can specify its name with the \f(CW\*(C`INTO\*(C'\fR keyword. .PP .Vb 3 \& [% WRAPPER "foo.tt" INTO wrapped_content WITH title = "Foo!" %] \& ... \& [% END %] .Ve .PP This is a syntactic sugar to template cascading. Here is a counterpart of the example in Kolon. .PP .Vb 4 \& : macro my_content \-> { \& Hello, world! \& : } \& : cascade "file.tx" { content => my_content() } .Ve .PP Note that the \s-1WRAPPER\s0 option () in Template-Toolkit is not supported directly. Instead, you can emulate it with \f(CW\*(C`header\*(C'\fR and \f(CW\*(C`footer\*(C'\fR options as follows: .PP .Vb 3 \& my %vpath = ( \& wrap_begin => \*(Aq[% WRAPPER "base" %]\*(Aq, \& wrap_end => \*(Aq[% END %]\*(Aq, \& \& base => \*(AqHello, [% content %] world!\*(Aq . "\en", \& content => \*(AqXslate\*(Aq, \& ); \& \& my $tx = Text::Xslate\->new( \& syntax => \*(AqTTerse\*(Aq, \& path => \e%vpath, \& \& header => [\*(Aqwrap_begin\*(Aq], \& footer => [\*(Aqwrap_end\*(Aq], \& ); \& \& print $tx\->render(\*(Aqcontent\*(Aq); # => Hello, Xslate world!; .Ve .SS "Macro blocks" .IX Subsection "Macro blocks" Definition: .PP .Vb 3 \& [% MACRO foo BLOCK \-%] \& This is a macro. \& [% END \-%] \& \& [% MACRO add(a, b) BLOCK \-%] \& [% a + b \-%] \& [% END \-%] .Ve .PP Call: .PP .Vb 2 \& [% foo() %] \& [% add(1, 2) %] .Ve .PP Unlike Template-Toolkit, calling macros requires parens (\f(CW\*(C`()\*(C'\fR). .SS "Virtual methods" .IX Subsection "Virtual methods" A few methods are supported in the Xslate core. .PP .Vb 3 \& %% a.size(); \& %% a.join(", "); \& %% a.reverse(); \& \& %% h.size(); \& %% h.keys(); \& %% h.values(); \& %% h.kv(); .Ve .PP However, there is a bridge mechanism that allows you to use external methods. For example, Text::Xslate::Bridge::TT2 provides the \s-1TT2\s0 virtual methods for Xslate, which bridges Template::VMethods implementation. .PP .Vb 1 \& use Text::Xslate::Bridge::TT2; \& \& my $tx = Text::Xslate\->new( \& syntax => \*(AqTTerse\*(Aq, \& module => [qw(Text::Xslate::Bridge::TT2)], \& ); \& \& print $tx\->render_string(\*(Aq[% "foo".length() %]\*(Aq); # => 3 .Ve .PP See Text::Xslate::Bridge, or search for \f(CW\*(C`Text::Xslate::Bridge::*\*(C'\fR on \s-1CPAN.\s0 .SS "Misc." .IX Subsection "Misc." \&\s-1CALL\s0 evaluates expressions, but does not print it. .PP .Vb 1 \& [% CALL expr %] .Ve .PP \&\s-1SET\s0 and assignments, although the use of them are strongly discouraged. .PP .Vb 2 \& [% SET var1 = expr1, var2 = expr2 %] \& [% var = expr %] .Ve .PP \&\s-1DEFAULT\s0 statements as a syntactic sugar to \f(CW\*(C`SET var = var // expr\*(C'\fR: .PP .Vb 1 \& [% DEFAULT lang = "TTerse" %] .Ve .PP \&\s-1FILTER\s0 blocks to apply filters to text sections: .PP .Vb 3 \& [% FILTER html \-%] \& Hello, world! \& [% END \-%] .Ve .SH "COMPATIBILITY" .IX Header "COMPATIBILITY" There are some differences between TTerse and Template-Toolkit. .IP "\(bu" 4 \&\f(CW\*(C`INCLUDE\*(C'\fR of TTerse requires an expression for the file name, while that of Template-Toolkit allows a bare token: .Sp .Vb 2 \& [% INCLUDE foo.tt # doesn\*(Aqt work! %] \& [% INCLUDE "foo.tt" # OK %] .Ve .IP "\(bu" 4 \&\f(CW\*(C`FOREACH item = list\*(C'\fR is forbidden in TTerse. It must be \f(CW\*(C`FOREACH item IN list\*(C'\fR. .IP "\(bu" 4 TTerse does not support plugins (i.e. \f(CW\*(C`USE\*(C'\fR directive), but understands the \f(CW\*(C`USE\*(C'\fR keyword as an alias to \f(CW\*(C`CALL\*(C'\fR, so you could use some simple plugins which do not depend on the context object of Template-Toolkit. .Sp .Vb 2 \& use Template::Plugin::Math; \& use Template::Plugin::String; \& \& my $tt = Text::Xslate\->new(...); \& \& mt %vars = ( \& Math => Template::Plugin::Math\->new(), # as a namespace \& String => Template::Plugin::String\->new(), # as a prototype \& ); \& print $tt\->render_string(<<\*(AqT\*(Aq, \e%vars); \& [% USE Math # does nothing actually, only for compatibility %] \& [% USE String %] \& [% Math.abs(\-100) # => 100 %] \& [% String.new("foo").upper # => FOO %] .Ve .IP "\(bu" 4 The following directives are not supported: \&\f(CW\*(C`INSERT\*(C'\fR, \f(CW\*(C`PROCESS\*(C'\fR, \f(CW\*(C`BLOCK\*(C'\fR as a named blocks, \f(CW\*(C`USE\*(C'\fR (but see above), \&\f(CW\*(C`PERL\*(C'\fR, \f(CW\*(C`RAWPERL\*(C'\fR, \f(CW\*(C`TRY\*(C'\fR, \f(CW\*(C`THROW\*(C'\fR, \&\f(CW\*(C`RETURN\*(C'\fR, \f(CW\*(C`STOP\*(C'\fR, \f(CW\*(C`CLEAR\*(C'\fR, \f(CW\*(C`META\*(C'\fR, \f(CW\*(C`TAGS\*(C'\fR, \f(CW\*(C`DEBUG\*(C'\fR, and \f(CW\*(C`VIEW\*(C'\fR. .Sp Some might be supported in a future. .SH "SEE ALSO" .IX Header "SEE ALSO" Text::Xslate .PP Template (Template::Toolkit) .PP Template::Tiny .PP Text::Xslate::Bridge::TT2 .PP Text::Xslate::Bridge::TT2Like .PP Text::Xslate::Bridge::Alloy