API - CoTemplate\XTemplate
system\cotemplate.php at line 17

Class XTemplate

XTemplate

public class XTemplate

Minimalistic XTemplate implementation for Cotonti

Field Summary
protected array Blocks

$blocks

protected static string Cache directory path

$cache_dir

protected static bool Enables disk caching of precompiled templates

$cache_enabled

protected static array Stores debug data

$debug_data

protected static boolean Enables debug dumping

$debug_mode

protected static boolean Prints debug mode screen

$debug_output

protected array Blocks already displayed (for debug mode)

$displayed_blocks

string Template file name

$filename

private bool Indicates that root-level blocks were found during another run

$found

protected array Index for quick block search.

$index

Maps block paths to actual array indices.

protected array

$tags

Contains a list of names of all tags present in the template

array Assigned template vars

$vars

Constructor Summary
void

__construct(string path)

Simplified constructor

Method Summary
string

__toString()

TPL code representation of the entire CoTemplate object for debugging

XTemplate

assign(mixed name, mixed val, string prefix)

Assigns a template variable or an array of them

static array

debugData()

Returns debug data dumped by CoTemplate if debug option is on.

static string

debugVar(string name, mixed value)

Debugging output of a tag name and current value

mixed

get(string name)

Returns current template variable value

array

getTags()

Returns the list of names of all tags present in the template

boolean

hasBlock(string name)

Returns TRUE if the block is present in template or FALSE otherwise

boolean

hasTag(string name)

Returns TRUE if the tag is present in template or FALSE otherwise

static void

init(array options)

Initializes static class configuration.

private static string

restart_include_files(array m)

restart() replace callback for FILE inclusion

private string

restart_root_blocks(array m)

restart() replace callback for root-level blocks

XTemplate

restart(string path)

Loads template file structure into memory

XTemplate

compile(string code)

Compiles the template from raw TPL code.

private static string

substitute_var(array m)

PCRE callback which immediately subsitutes a TPL var with its value

XTemplate

out(string block)

Prints a parsed block

XTemplate

parse(string block)

Parses a block

XTemplate

reset(string block)

Clears a parset block data

string

text(string block)

Returns parsed block HTML

Field Detail

system\cotemplate.php at line 30

blocks

protected array Blocks $blocks = array()

system\cotemplate.php at line 52

cache_dir

protected static string Cache directory path $cache_dir = ''

system\cotemplate.php at line 48

cache_enabled

protected static bool Enables disk caching of precompiled templates $cache_enabled = false

system\cotemplate.php at line 56

debug_data

protected static array Stores debug data $debug_data = array()

system\cotemplate.php at line 60

debug_mode

protected static boolean Enables debug dumping $debug_mode = false

system\cotemplate.php at line 64

debug_output

protected static boolean Prints debug mode screen $debug_output = false

system\cotemplate.php at line 34

displayed_blocks

protected array Blocks already displayed (for debug mode) $displayed_blocks = array()

system\cotemplate.php at line 22

filename

public string Template file name $filename = ''

system\cotemplate.php at line 68

found

private bool Indicates that root-level blocks were found during another run $found = false

system\cotemplate.php at line 39

index

protected array Index for quick block search. $index = array()
Maps block paths to actual array indices.

system\cotemplate.php at line 44

tags

protected array $tags = null
Contains a list of names of all tags present in the template

system\cotemplate.php at line 26

vars

public array Assigned template vars $vars = array()

Constructor Detail

system\cotemplate.php at line 75

__construct

public void __construct(string path)
Simplified constructor
Parameters:
path - Template file name

Method Detail

system\cotemplate.php at line 97

__toString

public string __toString()
TPL code representation of the entire CoTemplate object for debugging
Returns:

system\cotemplate.php at line 115

assign

public XTemplate assign(mixed name, mixed val, string prefix)
Assigns a template variable or an array of them
Parameters:
name - Variable name or array of values
val - Tag value if $name is not an array
prefix - An optional prefix for variable keys
Returns:
$this object for call chaining

system\cotemplate.php at line 149

debugData

public static array debugData()
Returns debug data dumped by CoTemplate if debug option is on. Debug data has the following format: array( 'filename.tpl' => array( 'BLOCK.NAME' => array( 'TAG_NAME' => 'tag value', // ... ), // ... ), // ... );
Returns:
Debug dump

system\cotemplate.php at line 161

debugVar

public static string debugVar(string name, mixed value)
Debugging output of a tag name and current value
Parameters:
name - Tag name
value - Tag value, will be casted to string
Returns:
A list elemented for debug output

system\cotemplate.php at line 188

get

public mixed get(string name)
Returns current template variable value
Parameters:
name - Variable name
Returns:

system\cotemplate.php at line 197

getTags

public array getTags()
Returns the list of names of all tags present in the template
Returns:

system\cotemplate.php at line 216

hasBlock

public boolean hasBlock(string name)
Returns TRUE if the block is present in template or FALSE otherwise
Parameters:
name - Full block name including dots and parent blocks
Returns:

system\cotemplate.php at line 226

hasTag

public boolean hasTag(string name)
Returns TRUE if the tag is present in template or FALSE otherwise
Parameters:
name - Tag name (case-sensitive)
Returns:

system\cotemplate.php at line 258

init

public static void init(array options)
Initializes static class configuration. Options: * cache - Enable template pre-compilation on disk. * cache_dir - Directory to store pre-compiled templates. * cleanup - Cleanup HTML output removing comments, spaces and blanks. * debug - Enable dumping debug information. * debug_output - Switch output to TPL-debug mode. Default values: $options = array( 'cache' => false, 'cache_dir' => '', 'cleanup' => false, 'debug' => false, 'debug_output' => false, );
Parameters:
options - CoTemplate options

system\cotemplate.php at line 283

restart_include_files

private static string restart_include_files(array m)
restart() replace callback for FILE inclusion
Parameters:
m - PCRE matches
Returns:

system\cotemplate.php at line 302

restart_root_blocks

private string restart_root_blocks(array m)
restart() replace callback for root-level blocks
Parameters:
m - PCRE matches
Returns:

system\cotemplate.php at line 318

restart

public XTemplate restart(string path)
Loads template file structure into memory
Parameters:
path - Template file path
Returns:
$this object for call chaining

system\cotemplate.php at line 379

compile

public XTemplate compile(string code)
Compiles the template from raw TPL code. Example: $raw_tpl = file_get_contents('some/file.tpl'); // Process $raw_tpl code here $t = new XTemplate(); $t->compile($raw_tpl); // Use $t as normal XTemplate object
Parameters:
code - Raw template source code
Returns:
$this object for call chaining

system\cotemplate.php at line 401

substitute_var

private static string substitute_var(array m)
PCRE callback which immediately subsitutes a TPL var with its value
Parameters:
m - PCRE matches
Returns:

system\cotemplate.php at line 413

out

public XTemplate out(string block)
Prints a parsed block
Parameters:
block - Block name
Returns:
$this object for call chaining

system\cotemplate.php at line 455

parse

public XTemplate parse(string block)
Parses a block
Parameters:
block - Block name
Returns:
$this object for call chaining

system\cotemplate.php at line 519

reset

public XTemplate reset(string block)
Clears a parset block data
Parameters:
block - Block name
Returns:
$this object for call chaining

system\cotemplate.php at line 548

text

public string text(string block)
Returns parsed block HTML
Parameters:
block - Block name
Returns: