]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - lib/CGI/Ex/Template.pod
CGI::Ex 2.12
[chaz/p5-CGI-Ex] / lib / CGI / Ex / Template.pod
index f93126132525f6d91f90902d6b35e0580284b2ae..206dcba50de481df56efca3a6b77f2b064406ca2 100644 (file)
@@ -15,9 +15,14 @@ CGI::Ex::Template - Fast and lightweight TT2/3 template engine
         hash => {a => 'b'},
     };
 
+    # print to STDOUT
     $t->process('my/template.tt', $swap)
         || die $t->error;
 
+    # process into a variable
+    my $out = '';
+    $t->process('my/template.tt', $swap, \$out);
+
     ### CET uses the same syntax and configuration as Template::Toolkit
 
 =head1 DESCRIPTION
@@ -180,9 +185,7 @@ to Template::Stash::define_vmethod.
 
 =head1 TODO
 
-    Add WRAPPER configuration item (the WRAPPER directive is supported).
-
-    Add ERROR config item
+    Add HTML::Template support
 
 =head1 HOW IS CGI::Ex::Template DIFFERENT
 
@@ -403,6 +406,14 @@ Used for Data::Dumpering the passed variable or expression.
         PRE_CHOMP => '-'
    %]
 
+=item Configuration options can use lowercase names instead
+of the all uppercase names that TT2 uses.
+
+    my $t = CGI::Ex::Template->new({
+        anycase     => 1,
+        interpolate => 1,
+    });
+
 =item CET does not generate Perl code.
 
 It generates an "opcode" tree.  The opcode tree is an arrayref
@@ -1623,6 +1634,13 @@ Arguments may also be passed to the template:
 Filenames must be relative to INCLUDE_PATH unless the ABSOLUTE
 or RELATIVE configuration items are set.
 
+Multiple filenames can be passed by separating them with a plus, a space,
+or commas (TT2 doesn't support the comma).  Any supplied arguments will
+be used on all templates.
+
+    [% INCLUDE "path/to/template.html",
+               "path/to/template2.html" a = "An arg" b = "Another arg" %]
+
 =item C<INSERT>
 
 Insert the contents of a file without template parsing.
@@ -1630,6 +1648,12 @@ Insert the contents of a file without template parsing.
 Filenames must be relative to INCLUDE_PATH unless the ABSOLUTE
 or RELATIVE configuration items are set.
 
+Multiple filenames can be passed by separating them with a plus, a space,
+or commas (TT2 doesn't support the comma).
+
+    [% INSERT "path/to/template.html",
+              "path/to/template2.html" %]
+
 =item C<LAST>
 
 Used to exit out of a WHILE or FOREACH loop.
@@ -1724,6 +1748,13 @@ Arguments may also be passed to the template:
 Filenames must be relative to INCLUDE_PATH unless the ABSOLUTE
 or RELATIVE configuration items are set.
 
+Multiple filenames can be passed by separating them with a plus, a space,
+or commas (TT2 doesn't support the comma).  Any supplied arguments will
+be used on all templates.
+
+    [% PROCESS "path/to/template.html",
+               "path/to/template2.html" a = "An arg" b = "Another arg" %]
+
 =item C<RAWPERL>
 
 Only available if the EVAL_PERL configuration item is true (default is false).
@@ -2037,8 +2068,8 @@ Block directive.  Processes contents of its block and then passes them
 in the [% content %] variable to the block or filename listed in the
 WRAPPER tag.
 
-    [% WRAPPER foo %]
-    My content to be processed.[% a = 2 %]
+    [% WRAPPER foo b = 23 %]
+    My content to be processed ([% b %]).[% a = 2 %]
     [% END %]
 
     [% BLOCK foo %]
@@ -2050,10 +2081,10 @@ WRAPPER tag.
 This would print.
 
     A header (2).
-    My content to be processed.
+    My content to be processed (23).
     A footer (2).
 
-The WRAPPER directive may also be used as a post directive.
+The WRAPPER directive may also be used as a post operative directive.
 
     [% BLOCK baz %]([% content %])[% END -%]
     [% "foobar" WRAPPER baz %]
@@ -2062,6 +2093,17 @@ Would print
 
     (foobar)');
 
+Multiple filenames can be passed by separating them with a plus, a space,
+or commas (TT2 doesn't support the comma).  Any supplied arguments will
+be used on all templates.  Wrappers are processed in reverse order, so
+that the first wrapper listed will surround each subsequent wrapper listed.
+Variables from inner wrappers are available to the next wrapper that
+surrounds it.
+
+    [% WRAPPER "path/to/outer.html",
+               "path/to/inner.html" a = "An arg" b = "Another arg" %]
+
+
 =back
 
 
@@ -2585,6 +2627,37 @@ Any of the Data::Dumper configuration items may be passed.
 
 Set a string to use as the closing delimiter for TT.  Default is "%]".
 
+=item ERROR
+
+Used as a fall back when the processing of a template fails.  May either
+be a single filename that will be used in all cases, or may be a hashref
+of options where the keynames represent error types that will be handled
+by the filename in their value.  A key named default will be used if no
+other matching keyname can be found.  The selection process is similar
+to that of the TRY/CATCH/THROW directives (see those directives for more
+information).
+
+    my $t = CGI::Ex::Template->new({
+        ERROR => 'general/catch_all_errors.html',
+    });
+
+    my $t = CGI::Ex::Template->new({
+        ERROR => {
+            default   => 'general/catch_all_errors.html',
+            foo       => 'catch_all_general_foo_errors.html',
+            'foo.bar' => 'catch_foo_bar_errors.html',
+        },
+    });
+
+Note that the ERROR handler will only be used for errors during the
+processing of the main document.  It will not catch errors that
+occur in templates found in the PRE_PROCESS, POST_PROCESS, and WRAPPER
+configuration items.
+
+=item ERRORS
+
+Same as the ERROR configuration item.  Both may be used interchangably.
+
 =item EVAL_PERL
 
 Boolean.  Default false.  If set to a true value, PERL and RAWPERL blocks
@@ -2681,6 +2754,16 @@ Is the same as
 
 Any number of hashes can be added to the NAMESPACE hash.
 
+=item NEGATIVE_STAT_TTL (Not in TT)
+
+Defaults to STAT_TTL which defaults to $STAT_TTL which defaults to 1.
+
+Similar to STAT_TTL - but represents the time-to-live
+seconds until a document that was not found is checked again against
+the 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.
+
 =item OUTPUT
 
 Alternate way of passing in the output location for processed templates.
@@ -2761,6 +2844,14 @@ that are relative to the currently running process.
 
 Set a string to use as the opening delimiter for TT.  Default is "[%".
 
+=item 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.
+
 =item TAG_STYLE
 
 Allow for setting the type of tag delimiters to use for parsing the TT.
@@ -2842,21 +2933,30 @@ A hashref of variables to initialize the template stash with.  These
 variables are available for use in any of the executed templates.
 See the section on VARIABLES for the types of information that can be passed in.
 
-=back
+=item WRAPPER
 
+Operates similar to the WRAPPER directive.  The option can be given a
+single filename, or an arrayref of filenames that will be used to wrap
+the processed content.  If an arrayref is passed the filenames are
+processed in reverse order, so that the first filename specified will
+end up being on the outside (surrounding all other wrappers).
 
+   my $t = CGI::Ex::Template->new(
+       WRAPPER => ['my/wrappers/outer.html', 'my/wrappers/inner.html'],
+   );
 
-=head1 UNSUPPORTED TT CONFIGURATION
+Content generated by the PRE_PROCESS and POST_PROCESS will come before
+and after (respectively) the content generated by the WRAPPER
+configuration item.
 
-=over 4
+See the WRAPPER direcive for more examples of how wrappers are construted.
 
-=item WRAPPER
+=back
 
-This will be supported - just not done yet.
 
-=item ERROR
+=head1 UNSUPPORTED TT CONFIGURATION
 
-This will be supported - just not done yet.
+=over 4
 
 =item LOAD_TEMPLATES
 
@@ -2915,7 +3015,9 @@ filters, and perl blocks.
 
 CGI::Ex::Template has its own built in parser.  The closest similarity is
 the parse_tree method.  The output of parse_tree is an optree that is
-later run by execute_tree.
+later run by execute_tree.  CET provides a backend to the Template::Parser::CET
+module which can be used to replace the default parser when using
+the standard Template::Toolkit library.
 
 =item GRAMMAR
 
This page took 0.032178 seconds and 4 git commands to generate.