Class Horde_Template
Horde Template system. Adapted from bTemplate by Brian Lozier
brian@massassi.net.
Horde_Template provides a basic template engine with tags, loops,
and if conditions. However, it is also a simple interface with
several essential functions: set(), fetch(), and
parse(). Subclasses or decorators can implement (or delegate) these
three methods, plus the options api, and easily implement other
template engines (PHP code, XSLT, etc.) without requiring usage
changes.
Compilation code adapted from code written by Bruno Pedro bpedro@ptm.pt.
Copyright 2002-2012 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you
did not receive this file, see http://www.horde.org/licenses/lgpl21.
Methods summary
public
|
#
__construct( array $params = array() )
Constructor.
Parameters
- $params
- The following configuration options:
<pre><span class="php-quote">'basepath'</span> - (string) The directory where templates are read from.
<span class="php-quote">'cacheob'</span> - (Horde_Cache) A caching object used to cache the output.
<span class="php-quote">'logger'</span> - (Horde_Log_Logger) A logger object.</pre>
|
public
|
#
setOption( string $option, mixed $val )
Sets an option.
Currently available options are:
<
pre>
'debug' - Output debugging information to screen
'forcecompile' - Force a compilation on every page load
'gettext' - Activate gettext detection
<
pre>
Sets an option.
Currently available options are:
<
pre>
'debug' - Output debugging information to screen
'forcecompile' - Force a compilation on every page load
'gettext' - Activate gettext detection
<
pre>
Parameters
- $option
- The option name.
- $val
- The option's value.
|
public
|
#
setTemplate( string $template )
Set the template contents to a string.
Set the template contents to a string.
Parameters
- $template
- The template text.
|
public
mixed
|
#
getOption( string $option )
Returns an option's value.
Returns an option's value.
Parameters
Returns
mixed The option's value.
|
public
|
#
set( string|array $tag, mixed $var )
Sets a tag, loop, or if variable.
Sets a tag, loop, or if variable.
Parameters
- $tag
- <p>Either the tag name or a hash with tag names
as keys and tag values as values.</p>
- $var
- The value to replace the tag with.
|
public
mixed
|
#
get( string $tag )
Returns the value of a tag or loop.
Returns the value of a tag or loop.
Parameters
Returns
mixed The tag value or null if the tag hasn't been set yet.
|
public
string
|
#
fetch( string $filename = null )
Fetches a template from the specified file and return the parsed
contents.
Fetches a template from the specified file and return the parsed
contents.
Parameters
- $filename
- The file to fetch the template from.
Returns
string The parsed template.
|
public
string
|
#
parse( string $contents = null )
Parses all variables/tags in the template.
Parses all variables/tags in the template.
Parameters
- $contents
- The unparsed template.
Returns
string The parsed template.
|
Constants summary
string |
TEMPLATE_STRING
The identifier to use for memory-only templates.
The identifier to use for memory-only templates.
|
|