This shows you the differences between two versions of the page.
esmith:template [2015/05/22 08:12] stephdl [Template Variables] |
esmith:template [2019/06/05 19:48] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== esmith:: | ||
- | | ||
- | |||
- | In a root terminal you can do the command below if you want to display the up-to-date content | ||
- | | ||
- | |||
- | ===== VERSION ===== | ||
- | This file documents " | ||
- | |||
- | ===== SYNOPSIS ===== | ||
- | use esmith:: | ||
- | | ||
- | |||
- | ===== DESCRIPTION ===== | ||
- | This is the interface to the E-Smith templating system. | ||
- | |||
- | esmith:: | ||
- | |||
- | ===== Template Variables ===== | ||
- | |||
- | The following variables are available to all templates. | ||
- | |||
- | ===== $confref ===== | ||
- | DEPRECATED. | ||
- | |||
- | ===== $DB ===== | ||
- | Contains a reference to an esmith:: | ||
- | |||
- | |||
- | In addition, each record in the default esmith configuration database (configuration) is available as a hash if it has multiple properties(where each key/value is a property of the record) or if it has a single property (type) then it given as a scalar. | ||
- | |||
- | So you can say: | ||
- | |||
- | { $DomainName } # $configdb-> | ||
- | { $sshd{status} } # $configdb-> | ||
- | Finally, variables from additional databases are usually gotten via the esmith:: | ||
- | |||
- | | ||
- | my %Hosts = esmith:: | ||
- | ... | ||
- | } | ||
- | |||
- | ===== Functions ===== | ||
- | |||
- | |||
- | | ||
- | | ||
- | | ||
- | }); | ||
- | |||
- | | ||
- | | ||
- | | ||
- | }); | ||
- | processTemplate() expands a set of templates based on the keys/values in %config. | ||
- | |||
- | The options to processTemplate are as follows... | ||
- | |||
- | ==== MORE_DATA ==== | ||
- | A hash ref containing additional variables you’d like to put into the template. | ||
- | |||
- | # $Foo = ’bar’ | ||
- | | ||
- | |||
- | Any keys in MORE_DATA will override those from the default | ||
- | | ||
- | |||
- | This replaces CONFREF. | ||
- | |||
- | ==== CONFREF ==== | ||
- | DEPRECATED. | ||
- | |||
- | This is usually a tied esmith:: | ||
- | |||
- | This has been replaced by MORE_DATA and cannot be used in conjunction. | ||
- | |||
- | ==== TEMPLATE_PATH ==== | ||
- | Full path to the file which fill result from this template. | ||
- | For example, ’/ | ||
- | |||
- | ==== TEMPLATE_EXPAND_QUEUE ==== | ||
- | List of directories to scan for templates. | ||
- | defaults to: | ||
- | |||
- | / | ||
- | / | ||
- | |||
- | it then appends the TEMPLATE_PATH to this, so the resulting search might be: | ||
- | |||
- | / | ||
- | / | ||
- | |||
- | All templates found are combined in ASCIIbetical order to produce the final file. The exception to this is template-begin, | ||
- | |||
- | If no template-begin is found the one in / | ||
- | |||
- | If two directories contain the same template those eariler in the queue will override those later. | ||
- | |||
- | ==== OUTPUT_PREFIX ==== | ||
- | Directory which contains the OUTPUT_FILENAME. | ||
- | |||
- | ==== OUTPUT_FILENAME ==== | ||
- | The file which results from this template. | ||
- | Defaults to the TEMPLATE_PATH. | ||
- | ==== FILTER ==== | ||
- | A code ref through which each line of the resulting text is fed, for example: | ||
- | |||
- | | ||
- | |||
- | would put a # in front of each line of the template. | ||
- | |||
- | | ||
- | will remove all lines that contain only whitespace. | ||
- | |||
- | UID | ||
- | GID The user and group ID by which the resulting file should be | ||
- | | ||
- | root. | ||
- | |||
- | Defaults to UID 0 and GID 0. | ||
- | |||
- | ==== PERMS ==== | ||
- | File permissions which the resulting file should be set to have. | ||
- | |||
- | | ||
- | |||
- | ==== OUTPUT_TYPE ==== | ||
- | Determines if the filled in template should go straight to a file or be returned by processTemplate(). | ||
- | |||
- | | ||
- | | ||
- | |||
- | Defaults to ’file’ | ||
- | For example we have a template / | ||
- | |||
- | # Records from esmith:: | ||
- | | ||
- | | ||
- | }); | ||
- | |||
- | Example 2: we have a template / | ||
- | |||
- | Solution: | ||
- | |||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | ], | ||
- | | ||
- | | ||
- | | ||
- | UID => $username, | ||
- | GID => $username, | ||
- | PERMS => 0644, | ||
- | }); | ||
- | |||
- | Example 3: we have a template fragment / | ||
- | |||
- | Solution: In the 80VirtualHosts fragment, we use the OUTPUT_TYPE=’string’ option to return the output of processTemplate for each VirtualHost as a string, and then we add the results to the $OUT variable for inclusion in the httpd.conf template expansion. | ||
- | |||
- | | ||
- | { | ||
- | # the $OUT variable stores the output of this template fragment | ||
- | use esmith:: | ||
- | $OUT .= processTemplate ( | ||
- | { | ||
- | | ||
- | virtualHosts => \@virtualHosts, | ||
- | virtualHostContent => \%virtualHostContent }, | ||
- | | ||
- | | ||
- | }); | ||
- | } | ||
- | |||
- | ==== Filters ==== | ||
- | |||
- | Filters are an experimental feature which allow you to filter the output of a template in various ways. | ||
- | |||
- | Filtering functions take a single line at a time and return the filtered version. | ||
- | |||
- | ==== removeBlankLines ==== | ||
- | Removes empty lines or those containing only whitespace from a template. | ||
- | |||
- | ===== SEE ALSO ===== | ||
- | http:// | ||
- | |||
- | [http:// | ||
- | |||
- | ===== AUTHOR ===== | ||
- | Mitel Networks Corporation | ||
- | For more information, | ||
- | |||
- | {{tag> neth-development sme-development }} | ||
- | |||
- | [[Category: | ||
- | [[Category: | ||