Changes

From SME Server
Jump to navigationJump to search
14 bytes added ,  23:00, 21 December 2013
Line 125: Line 125:  
=== Philosophy ===
 
=== Philosophy ===
   −
When people make a template module like this one, they almost always start by inventing a special syntax for substitutions.  For example, they build it so that a string like "%%VAR%%" is replaced with the value of $VAR.  Then they realize the need extra formatting, so they put in some special syntax for formatting.  Then they need a loop, so they invent a loop syntax.  Pretty soon they have a new little template language.
+
When people make a template module like this one, they almost always start by inventing a special syntax for substitutions.  For example, they build it so that a string like "%%VAR%%" is replaced with the value of $VAR.  Then they realize the need extra formatting, so they put in some special syntax for formatting.  Then they need a loop, so they invent a loop syntax.  Pretty soon they have a new little template language.<br />
This approach has two problems: First, their little language is crippled. If you need to do something the author hasn’t thought of, you lose.  Second: Who wants to learn another language?  You already know Perl, so why not use it?
+
 
 +
This approach has two problems: First, their little language is crippled. If you need to do something the author hasn’t thought of, you lose.  Second: Who wants to learn another language?  You already know Perl, so why not use it?<br />
 +
 
    
"Text::Template" templates are programmed in Perl.  You embed Perl code in your template, with "{" at the beginning and "}" at the end.  If you want a variable interpolated, you write it the way you would in Perl. If you need to make a loop, you can use any of the Perl loop constructions.  All the Perl built-in functions are available.
 
"Text::Template" templates are programmed in Perl.  You embed Perl code in your template, with "{" at the beginning and "}" at the end.  If you want a variable interpolated, you write it the way you would in Perl. If you need to make a loop, you can use any of the Perl loop constructions.  All the Perl built-in functions are available.

Navigation menu