Documentation

Horde_Template
in package

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.

Tags
author

Chuck Hagenbuch chuck@horde.org

author

Michael Slusarz slusarz@horde.org

Table of Contents

TEMPLATE_STRING  = '**string'
The identifier to use for memory-only templates.
$_arrays  : array<string|int, mixed>
Loop tag values.
$_basepath  : string
Directory that templates should be read from.
$_cache  : Horde_Cache
The Horde_Cache object to use.
$_foreachMap  : array<string|int, mixed>
Foreach variable mappings.
$_foreachVar  : int
Foreach variable incrementor.
$_logger  : Horde_Log_Logger
Logger.
$_options  : array<string|int, mixed>
Option values.
$_pregcache  : array<string|int, mixed>
preg_match() cache.
$_scalars  : array<string|int, mixed>
Tag (scalar) values.
$_template  : string
Template source.
$_templateFile  : string
Path to template source.
__construct()  : mixed
Constructor.
fetch()  : string
Fetches a template from the specified file and return the parsed contents.
get()  : mixed
Returns the value of a tag or loop.
getOption()  : mixed
Returns an option's value.
parse()  : string
Parses all variables/tags in the template.
set()  : mixed
Sets a tag, loop, or if variable.
setOption()  : mixed
Sets an option.
setTemplate()  : mixed
Set the template contents to a string.
_doReplace()  : mixed
TODO
_doSearch()  : mixed
TODO
_generatePHPVar()  : mixed
Output the correct PHP variable string for use in template space.
_parse()  : mixed
Parses all variables/tags in the template.
_parseAssociativeTags()  : mixed
Parse associative tags (i.e. <tag:foo.bar />).
_parseGettext()  : mixed
Parses gettext tags.
_parseIf()  : mixed
Parses 'if' statements.
_parseLoop()  : mixed
Parses the given array for any loops or other uses of the array.
_parseTags()  : mixed
Replaces 'tag' tags with their PHP equivalents.

Constants

TEMPLATE_STRING

The identifier to use for memory-only templates.

public mixed TEMPLATE_STRING = '**string'

Properties

$_arrays

Loop tag values.

protected array<string|int, mixed> $_arrays = array()

$_basepath

Directory that templates should be read from.

protected string $_basepath = ''

$_cache

The Horde_Cache object to use.

protected Horde_Cache $_cache

$_foreachMap

Foreach variable mappings.

protected array<string|int, mixed> $_foreachMap = array()

$_foreachVar

Foreach variable incrementor.

protected int $_foreachVar = 0

$_logger

Logger.

protected Horde_Log_Logger $_logger

$_options

Option values.

protected array<string|int, mixed> $_options = array()

$_pregcache

preg_match() cache.

protected array<string|int, mixed> $_pregcache = array()

$_scalars

Tag (scalar) values.

protected array<string|int, mixed> $_scalars = array()

$_template

Template source.

protected string $_template = \null

$_templateFile

Path to template source.

protected string $_templateFile = \null

Methods

__construct()

Constructor.

public __construct([array<string|int, mixed> $params = array() ]) : mixed
Parameters
$params : array<string|int, mixed> = array()

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.
Return values
mixed

fetch()

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

public fetch([string $filename = null ]) : string
Parameters
$filename : string = null

The file to fetch the template from.

Return values
string

The parsed template.

get()

Returns the value of a tag or loop.

public get(string $tag) : mixed
Parameters
$tag : string

The tag name.

Return values
mixed

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

getOption()

Returns an option's value.

public getOption(string $option) : mixed
Parameters
$option : string

The option name.

Return values
mixed

The option's value.

parse()

Parses all variables/tags in the template.

public parse([string $contents = null ]) : string
Parameters
$contents : string = null

The unparsed template.

Return values
string

The parsed template.

set()

Sets a tag, loop, or if variable.

public set(string|array<string|int, mixed> $tag, mixed $var) : mixed
Parameters
$tag : string|array<string|int, mixed>

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

$var : mixed

The value to replace the tag with.

Return values
mixed

setOption()

Sets an option.

public setOption(string $option, mixed $val) : mixed

Currently available options are:

'debug' - Output debugging information to screen
'forcecompile' - Force a compilation on every page load
'gettext' - Activate gettext detection
Parameters
$option : string

The option name.

$val : mixed

The option's value.

Return values
mixed

setTemplate()

Set the template contents to a string.

public setTemplate(string $template) : mixed
Parameters
$template : string

The template text.

Return values
mixed

_doReplace()

TODO

protected _doReplace(mixed $replace) : mixed
Parameters
$replace : mixed
Return values
mixed

_doSearch()

TODO

protected _doSearch(mixed $tag, mixed $key[, mixed $noclose = false ]) : mixed
Parameters
$tag : mixed
$key : mixed
$noclose : mixed = false
Return values
mixed

_generatePHPVar()

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

protected _generatePHPVar(mixed $tag, mixed $key) : mixed
Parameters
$tag : mixed
$key : mixed
Return values
mixed

_parse()

Parses all variables/tags in the template.

protected _parse() : mixed
Return values
mixed

_parseAssociativeTags()

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

protected _parseAssociativeTags() : mixed
Return values
mixed

_parseGettext()

Parses gettext tags.

protected _parseGettext() : mixed
Tags
todo

Convert to use Horde_Translation.

Return values
mixed

_parseIf()

Parses 'if' statements.

protected _parseIf([string $key = null ]) : mixed
Parameters
$key : string = null

The key prefix to parse.

Return values
mixed

_parseLoop()

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

protected _parseLoop([string $key = null ]) : mixed
Parameters
$key : string = null

The key prefix to parse.

Return values
mixed

_parseTags()

Replaces 'tag' tags with their PHP equivalents.

protected _parseTags([string $key = null ]) : mixed
Parameters
$key : string = null

The key prefix to parse.

Return values
mixed

Search results