Rex::Template - Online Linux Manual PageSection : 3
Updated : 2021-03-06
Source : perl v5.32.1
Note : User Contributed Perl Documentation

NAMERex::Template − simple template engine

SYNOPSIS​ use Rex::Template; ​ ​ my $template = Rex::Template−>new; ​ ​ print $template−>parse($content, \%template_vars); ​ print $template−>parse($content, @template_vars);

DESCRIPTIONThis is a simple template engine for configuration files. It is included mostly for backwards compatibility, and it is recommended to use Rex::Template::NG instead (for better control of chomping new lines, and better diagnostics if things go wrong).

SYNTAXThe following syntax is recognized: • anything between <% and %> markers are considered as a template directive, which is treated as Perl code • if the opening marker is followed by an equal sign (<%=) or a plus sign (<%+), then the directive is replaced with the value it evaluates to • if the closing marker is prefixed with a minus sign (−%>), then any trailing newlines are chomped for that directive The built-in template support is intentionally kept basic and simple. For anything more sophisticated, please use your favorite template engine.

EXAMPLESPlain text is unchanged: ​ my $result = $template−>parse( 'one two three', {} ); ​ ​ # $result is 'one two three' Variable interpolation: ​ my $result = template−>parse( 'Hello, this is <%= $::name %>', { name => 'foo' } ); # original format ​ my $result = template−>parse( 'Hello, this is <%+ $::name %>', { name => 'foo' } ); # alternative format with + sign ​ my $result = template−>parse( 'Hello, this is <%= $name %>', { name => 'foo' } ); # local variables ​ my $result = template−>parse( 'Hello, this is <%= $name %>', name => 'foo' ); # array of variables, instead of hashref ​ ​ # $result is 'Hello, this is foo' for all cases above Simple evaluation: ​ my $result = $template−>parse( '<%= join("/", @{$elements} ) %>', elements => [qw(one two three)] ); ​ # $result is 'one/two/three' Embedded code blocks: ​ my $content = '<% if ($logged_in) { %> ​ Logged in! ​ <% } else { %> ​ Logged out! ​ <% } %>'; ​ ​ my $result = $template−>parse( $content, logged_in => 1 ); ​ ​ # $result is "\nLogged in!\n"

DIAGNOSTICSNot much, mainly due to the internal approach of the module. If there was a problem, it prints an INFO level syntax error at ..., followed by a WARN about It seems that there was an error processing the template because the result is empty., and finally Error processing template at .... The beginning of the reported syntax error might give some clue where the error happened in the template, but that's it. Use Rex::Template::NG instead for better diagnostics.

CONFIGURATION AND ENVIRONMENTIf $Rex::Template::BE_LOCAL is set to a true value, then local template variables are supported instead of only global ones ($foo vs $::foo). The default value is 1 since Rex−0.41. It can be disabled with the no_local_template_vars feature flag. If $Rex::Template::DO_CHOMP is set to a true value, then any trailing new line character resulting from template directives are chomped. Defaults to 0. This module does not support any environment variables.

EXPORTED FUNCTIONS

parse($content, $variables)Parse $content as a template, using $variables hash reference to pass name-value pairs of variables to make them available for the template function. Alternatively, the variables may be passed as an array instead of a hash reference.

is_defined($variable, $default_value)This function will check if $variable is defined. If yes, it will return the value of $variable, otherwise it will return $default_value. You can use this function inside your templates, for example: ​ ServerTokens <%= is_defined( $::server_tokens, 'Prod' ) %>

DEPENDENCIES

INCOMPATIBILITIES

BUGS AND LIMITATIONSIt might not be able to chomp new line characters resulting from templates in every case. It can't report useful diagnostic messages upon errors. Use Rex::Template::NG instead.
0
Johanes Gumabo
Data Size   :   16,294 byte
man-Rex::Template.3pmBuild   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   2 / 174,584
Visitor ID   :     :  
Visitor IP   :   3.137.170.38   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|249|Rex::Template.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|Rex::Template.3pm|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|249|Rex::Template.3pm|43|br══─}─══|'br══─}─══ )         (htmlprn|149|Rex::Template.3pm|43|'br══─}─══ |'br══─}─══ )