Change book | Close bookmaker |
internal package
Foswiki::Templates internal package
Foswiki::Templates Support for Skin Template directives
The following tokens are supported by this language:
%TMPL:P% | Instantiates a previously defined template |
%TMPL:DEF% | Opens a template definition |
%TMPL:END% | Closes a template definition |
%TMPL:INCLUDE% | Includes another file of templates |
Note; the template cache does not get reset during initialisation, so the haveTemplate test will return true if a template was loaded during a previous run when used with mod_perl or speedycgi. Frustrating for the template author, but they just have to switch off the accelerators during development.
This is to all intents and purposes a singleton object. It could easily be coverted into a true singleton (template manager).
ClassMethod
new ( $session ) ObjectMethod
finish() ObjectMethod
haveTemplate( $name ) → $boolean Return true if the template exists and is loaded into the cache
ObjectMethod
expandTemplate( $params ) → $string tmplP
.
Examples:
$tmpls->expandTemplate("blah"); $tmpls->expandTemplate(context="view" then="sigh" else="humph");
ObjectMethod
tmplP( $attrs ) → $string context
, then
and else
values.
Recursively expands any contained TMPL:P tags.
Note that it would be trivial to add template parameters to this, simply by iterating over the other parameters (other than _DEFAULT, context, then and else) and doing a s/// in the template for that parameter value. This would add considerably to the power of templates.
ObjectMethod
readTemplate ( $name, %options ) → $text Reads a template, loading the definitions therein.
Return value: expanded template text
By default throws an OopsException if the template was not found or the access controls denied access. %options include:skin
- skin name,
web
- web to search
no_oops
- if true, will not throw an exception. Instead, returns undef.
If template text is found, extracts include statements and fully expands them. Also extracts template definitions and adds them to the list of loaded templates, overwriting any previous definition.