Class XTemplate

Description

XTemplate PHP templating engine

  • since: PHP 5
  • link: $HeadURL:
  • version:

    $Id: xtemplate.class.php 21 2007-05-29 18:01:15Z cocomp $

    XTemplate class - http://www.phpxtemplate.org/ (x)html / xml generation with templates - fast & easy Latest stable & Subversion versions available @ http://sourceforge.net/projects/xtpl/ License: LGPL / BSD - see license.txt Changelog: see changelog.txt

  • see: license.txt LGPL / BSD license
  • copyright: Barnabas Debreceni 2000-2001
  • author: Barnabas Debreceni [cranx@users.sourceforge.net]
  • copyright: Jeremy Coates 2002-2007
  • author: Jeremy Coates [cocomp@users.sourceforge.net]

Located in /xtemplate.class.php (line 25)


	
			
Direct descendents
Class Description
CachingXTemplate CachingXTemplate Extension to XTemplate to provide block level and whole template caching facilities Needs Web server writable directory
Variable Summary
Method Summary
XTemplate XTemplate (string $file, [string/array $tpldir = ''], [array $files = null], [string $mainblock = 'main'], [boolean $autosetup = true])
XTemplate __construct (string $file, [string/array $tpldir = ''], [array $files = null], [string $mainblock = 'main'], [boolean $autosetup = true])
void array_loop (string $bname, string $var, array &$values)
void assign (string $name, [string $val = ''], [boolean $reset_array = true])
void assign_file (string $name, [string $val = ''])
void clear_autoreset ()
boolean get_error ()
void insert_loop (string $bname, string $var, [string $value = ''])
void out (string $bname)
void out_file (string $bname, string $fname)
void parse (string $bname)
boolean parsed (string $bname)
void reset (string $bname)
void restart (string $file, [string/array $tpldir = ''], [array $files = null], [string $mainblock = 'main'], [boolean $autosetup = true], [string $tag_start = '{'], [string $tag_end = '}'])
void rparse (string $bname)
void scan_globals ()
void SetNullBlock (string $str, [string $bname = ''])
void SetNullString (string $str, [string $varname = ''])
void setup ([boolean $add_outer = false])
void set_autoreset ()
void set_null_block (string $str, [string $bname = ''])
void set_null_string (string $str, [string $varname = ''])
string text ([string $bname = ''])
string _getfile (string $file)
void _maketree (string $con, [string $parentblock = ''])
string _r_getfile (string $file)
array _store_filevar_parents (array $blocks)
Variables
array $blocks = array() (line 45)

Unparsed blocks

  • access: public
string $block_end_delim = '-->' (line 182)

Template block end delimiter

  • access: public
string $block_end_word = 'END:' (line 202)

Template block end word

The last 3 properties and this make the delimiters look like:

  • access: public
  • example: example not found
array $block_parse_order = array() (line 69)

Block parsing order for recursive parsing (Sometimes reverse :)

  • access: public
string $block_start_delim = '<!-- ' (line 174)

Template block start delimiter

  • access: public
string $block_start_word = 'BEGIN:' (line 190)

Template block start word

  • access: public
string $comment_preg = '( ?#.*?)?' (line 240)

Regular expression element for comments within tags and blocks

  • access: public
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
boolean $debug = false (line 264)

Debug mode

  • access: public
array $filecache = array() (line 111)

File caching during duration of script e.g. files only cached to speed {FILE "filename"} repeats

  • access: public
string $filecontents = '' (line 37)

Raw contents of the template file

  • access: public
string $filename = '' (line 135)

Template filename

  • access: public
null $files = null (line 127)

Filenames lookup table

  • access: public
array $filevars = array() (line 94)

File variables array

  • access: public
string $filevar_delim = '' (line 156)

RegEx for file include variable

"/\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}/m";

  • access: public
string $filevar_delim_nl = '' (line 166)

RegEx for file includes with newlines

"/^\s*\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}\s*\n/m";

  • access: public
array $filevar_parent = array() (line 102)

Filevars' parent block

  • access: public
string $file_delim = '' (line 146)

RegEx for file includes

"/\{FILE\s*\"([^\"]+)\"\s*\}/m";

  • access: public
string $mainblock = 'main' (line 248)

Default main template block name

  • access: public
string $output_type = 'HTML' (line 256)

Script output type

  • access: public
unknown_type $parsed_blocks = array() (line 52)

Parsed blocks

  • access: public
array $preparsed_blocks = array() (line 60)

Preparsed blocks (for file includes)

  • access: public
array $sub_blocks = array() (line 78)

Store sub-block names (For fast resetting)

  • access: public
string $tag_end_delim = '}' (line 226)

Template tag end delimiter

This makes the delimiters look like:

  • access: public
  • example: example not found
string $tag_start_delim = '{' (line 214)

Template tag start delimiter

This makes the delimiters look like:

  • access: public
  • example: example not found
string $tpldir = '' (line 119)

Location of template files

  • access: public
array $vars = array() (line 86)

Variables array

  • access: public
boolean $_autoreset = true (line 296)

Auto-reset sub blocks

  • access: protected
string $_error = '' (line 288)

Errors

  • access: protected
boolean $_ignore_missing_blocks = true (line 306)

Set to FALSE to generate errors if a non-existant blocks is referenced

  • access: protected
  • since: 2002/10/17
  • author: NW
array $_null_block = array('' => '') (line 280)

Null string for unassigned blocks

  • access: protected
array $_null_string = array('' => '') (line 272)

Null string for unassigned vars

  • access: protected
Methods
Constructor XTemplate (line 334)

PHP 4 Constructor - Instantiate the object

  • usedby: CachingXTemplate
  • access: public
  • deprecated: Use PHP 5 constructor instead
XTemplate XTemplate (string $file, [string/array $tpldir = ''], [array $files = null], [string $mainblock = 'main'], [boolean $autosetup = true])
  • string $file: Template file to work on
  • string/array $tpldir: Location of template files (useful for keeping files outside web server root)
  • array $files: Filenames lookup
  • string $mainblock: Name of main block in the template
  • boolean $autosetup: If true, run setup() as part of constuctor
Constructor __construct (line 318)

PHP 5 Constructor - Instantiate the object

  • access: public
XTemplate __construct (string $file, [string/array $tpldir = ''], [array $files = null], [string $mainblock = 'main'], [boolean $autosetup = true])
  • string $file: Template file to work on
  • string/array $tpldir: Location of template files (useful for keeping files outside web server root)
  • array $files: Filenames lookup
  • string $mainblock: Name of main block in the template
  • boolean $autosetup: If true, run setup() as part of constuctor

Redefined in descendants as:
array_loop (line 742)

parses a block for every set of data in the values array

  • access: public
void array_loop (string $bname, string $var, array &$values)
  • string $bname: Block name to loop
  • string $var: Variable to assign values to
  • array $values: Values to assign to $var
assign (line 464)

assign a variable

  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • access: public
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
  • example: example not found
void assign (string $name, [string $val = ''], [boolean $reset_array = true])
  • string $name: Variable to assign $val to
  • boolean $reset_array: Reset the variable array if $val is an array
  • string $val: / array $val Value to assign to $name

Redefined in descendants as:
assign_file (line 497)

assign a file variable

  • access: public
void assign_file (string $name, [string $val = ''])
  • string $name: Variable to assign $val to
  • string $val: / array $val Values to assign to $name

Redefined in descendants as:
clear_autoreset (line 897)

sets AUTORESET to 0. (default is 1) if set to 1, parse() automatically resets the parsed blocks' sub blocks (for multiple level blocks)

  • access: public
void clear_autoreset ()
get_error (line 929)

gets error condition / string

  • return: / string
  • access: public
boolean get_error ()
insert_loop (line 728)

inserts a loop ( call assign & parse )

  • access: public
void insert_loop (string $bname, string $var, [string $value = ''])
  • string $bname: Block name to assign
  • string $var: Variable to assign values to
  • string $value: / array $value Value to assign to $var
out (line 783)

prints the parsed text

  • access: public
void out (string $bname)
  • string $bname: Block name to echo out
out_file (line 799)

prints the parsed text to a specified file

  • access: public
void out_file (string $bname, string $fname)
  • string $bname: Block name to write out
  • string $fname: File name to write to
parse (line 517)

parse a block

  • access: public
void parse (string $bname)
  • string $bname: Block name to parse

Redefined in descendants as:
parsed (line 827)

returns true if block was parsed, false if not

  • access: public
boolean parsed (string $bname)
  • string $bname: Block name to test
reset (line 815)

resets the parsed text

  • access: public
void reset (string $bname)
  • string $bname: Block to reset
restart (line 362)

Restart the class - allows one instantiation with several files processed by restarting

e.g. $xtpl = new XTemplate('file1.xtpl'); $xtpl->parse('main'); $xtpl->out('main'); $xtpl->restart('file2.xtpl'); $xtpl->parse('main'); $xtpl->out('main'); (Added in response to sf:641407 feature request)

  • access: public
void restart (string $file, [string/array $tpldir = ''], [array $files = null], [string $mainblock = 'main'], [boolean $autosetup = true], [string $tag_start = '{'], [string $tag_end = '}'])
  • string $file: Template file to work on
  • string/array $tpldir: Location of template files
  • array $files: Filenames lookup
  • string $mainblock: Name of main block in the template
  • boolean $autosetup: If true, run setup() as part of restarting
  • string $tag_start: {
  • string $tag_end: }

Redefined in descendants as:
rparse (line 703)

returns the parsed text for a block, including all sub-blocks.

  • access: public
void rparse (string $bname)
  • string $bname: Block name to parse
scan_globals (line 907)

scans global variables and assigns to PHP array

  • access: public
void scan_globals ()
SetNullBlock (line 874)

Backwards compatibility only

  • access: public
  • deprecated: Change to set_null_block to keep in with rest of naming convention
void SetNullBlock (string $str, [string $bname = ''])
  • string $str
  • string $bname
SetNullString (line 851)

Backwards compatibility only

  • access: public
  • deprecated: Change to set_null_string to keep in with rest of naming convention
void SetNullString (string $str, [string $varname = ''])
  • string $str
  • string $varname
setup (line 407)

setup - the elements that were previously in the constructor

  • access: public
void setup ([boolean $add_outer = false])
  • boolean $add_outer: If true is passed when called, it adds an outer main block to the file
set_autoreset (line 885)

sets AUTORESET to 1. (default is 1) if set to 1, parse() automatically resets the parsed blocks' sub blocks (for multiple level blocks)

  • access: public
void set_autoreset ()
set_null_block (line 862)

sets the string to replace in case the block was not parsed

  • access: public
void set_null_block (string $str, [string $bname = ''])
  • string $str: Display string for null block
  • string $bname: Block name to apply $str to
set_null_string (line 839)

sets the string to replace in case the var was not assigned

  • access: public
void set_null_string (string $str, [string $varname = ''])
  • string $str: Display string for null block
  • string $varname: Variable name to apply $str to
text (line 760)

returns the parsed text for a block

  • access: public
string text ([string $bname = ''])
  • string $bname: Block name to return

Redefined in descendants as:
_getfile (line 1149)

returns the contents of a file

  • access: protected
string _getfile (string $file)
  • string $file
_maketree (line 964)

generates the array containing to-be-parsed stuff: $blocks["main"],$blocks["main.table"],$blocks["main.table.row"], etc.

also builds the reverse parse order.

  • access: public
void _maketree (string $con, [string $parentblock = ''])
  • string $con: content to be processed
  • string $parentblock: name of the parent block in the block hierarchy
_r_getfile (line 1258)

recursively gets the content of a file with {FILE "filename.tpl"} directives

  • access: public
string _r_getfile (string $file)
  • string $file
_store_filevar_parents (line 1110)

store container block's name for file variables

  • access: public
array _store_filevar_parents (array $blocks)
  • array $blocks

Documentation generated on Tue, 29 May 2007 19:29:36 +0100 by phpDocumentor 1.3.0RC3