\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-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Summary

Methods
Properties
Constants
__construct()
setOption()
setTemplate()
getOption()
set()
get()
fetch()
parse()
No public properties found
TEMPLATE_STRING
_parse()
_parseGettext()
_parseIf()
_parseLoop()
_parseTags()
_parseAssociativeTags()
_generatePHPVar()
_doSearch()
_doReplace()
$_cache
$_logger
$_options
$_basepath
$_scalars
$_arrays
$_templateFile
$_template
$_foreachMap
$_foreachVar
$_pregcache
N/A
No private methods found
No private properties found
N/A

Constants

TEMPLATE_STRING

TEMPLATE_STRING

The identifier to use for memory-only templates.

Properties

$_cache

$_cache : \Horde_Cache

The Horde_Cache object to use.

Type

\Horde_Cache

$_logger

$_logger : \Horde_Log_Logger

Logger.

Type

\Horde_Log_Logger

$_options

$_options : array

Option values.

Type

array

$_basepath

$_basepath : string

Directory that templates should be read from.

Type

string

$_scalars

$_scalars : array

Tag (scalar) values.

Type

array

$_arrays

$_arrays : array

Loop tag values.

Type

array

$_templateFile

$_templateFile : string

Path to template source.

Type

string

$_template

$_template : string

Template source.

Type

string

$_foreachMap

$_foreachMap : array

Foreach variable mappings.

Type

array

$_foreachVar

$_foreachVar : integer

Foreach variable incrementor.

Type

integer

$_pregcache

$_pregcache : array

preg_match() cache.

Type

array

Methods

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

The following configuration options:

'basepath' - (string) The directory where templates are read from.
'cacheob' - (Horde_Cache) A caching object used to cache the output.
'logger' - (Horde_Log_Logger) A logger object.

setOption()

setOption(string  $option, mixed  $val) 

Sets an option.

Currently available options are:

'debug' - Output debugging information to screen
'forcecompile' - Force a compilation on every page load
'gettext' - Activate gettext detection

                                    

Parameters

string $option

The option name.

mixed $val

The option's value.

setTemplate()

setTemplate(string  $template) 

Set the template contents to a string.

Parameters

string $template

The template text.

getOption()

getOption(string  $option) : mixed

Returns an option's value.

Parameters

string $option

The option name.

Returns

mixed —

The option's value.

set()

set(string|array  $tag, mixed  $var) 

Sets a tag, loop, or if variable.

Parameters

string|array $tag

Either the tag name or a hash with tag names as keys and tag values as values.

mixed $var

The value to replace the tag with.

get()

get(string  $tag) : mixed

Returns the value of a tag or loop.

Parameters

string $tag

The tag name.

Returns

mixed —

The tag value or null if the tag hasn't been set yet.

fetch()

fetch(string  $filename = null) : string

Fetches a template from the specified file and return the parsed contents.

Parameters

string $filename

The file to fetch the template from.

Returns

string —

The parsed template.

parse()

parse(string  $contents = null) : string

Parses all variables/tags in the template.

Parameters

string $contents

The unparsed template.

Returns

string —

The parsed template.

_parse()

_parse() 

Parses all variables/tags in the template.

_parseGettext()

_parseGettext() 

Parses gettext tags.

_parseIf()

_parseIf(string  $key = null) 

Parses 'if' statements.

Parameters

string $key

The key prefix to parse.

_parseLoop()

_parseLoop(string  $key = null) 

Parses the given array for any loops or other uses of the array.

Parameters

string $key

The key prefix to parse.

_parseTags()

_parseTags(string  $key = null) 

Replaces 'tag' tags with their PHP equivalents.

Parameters

string $key

The key prefix to parse.

_parseAssociativeTags()

_parseAssociativeTags() 

Parse associative tags (i.e. <tag:foo.bar />).

_generatePHPVar()

_generatePHPVar(  $tag,   $key) 

Output the correct PHP variable string for use in template space.

Parameters

$tag
$key

_doSearch()

_doSearch(  $tag,   $key,   $noclose = false) 

TODO

Parameters

$tag
$key
$noclose

_doReplace()

_doReplace(  $replace) 

TODO

Parameters

$replace