Gumbo_Template_Engine
Variables
- $_dir_cache
- $_dir_compile
- $_dir_config
- $_dir_tpl
- $_file
- $_formatted
- $_left_del
- $_output
- $_right_del
- $_vars
Methods
- assign
- display
- exists
- fetch
- getDirCache
- getDirCompile
- getDirConfig
- getDirTpl
- getFile
- getFullPath
- getLeftDelimeter
- getOutput
- getRightDelimeter
- getVar
- getVars
- isFormatted
- loadGlobals
- parse
- reset
- setDirCache
- setDirCompile
- setDirConfig
- setDirTpl
- setFile
- setFormatted
- setLeftDelimeter
- setOutput
- setRightDelimeter
- unassign
- __get
- __isset
- __set
- __unset
Abstract Template Engine Class
A Template Engine defines common methods involved in running template systems. There are many different ways to use template (PHP includes, string replacement, Smarty). A Template system will basically load a file, replacing keywords with values defined inside the program. Each Engine will define a specific implementation for parsing Template files.
The class provides a basic implementation. This allows an Engine to only override certain methods for custom implementation. The common methods allow access to Template variables (and assignment), setting the Template file name (file name or full path), setting the Template directory path (including extra Smarty defined paths), loading global Template settings, and setting the surrounding characters of keywords inside the Template file.
To create a new Template_Engine, simply extend this class, placing the new file into the 'gumbo/template/engine/*' directory. The name should be unique 'Gumbo_Template_Engine_[Name]'. The new Engine will be responsible for parsing a particular type of Template file. Details on how to use the Engine should be defined inside the class.
Template File The Template File can either be a simple file name (combined with the Template Directory) or a full path. When the Template File is parsed, the 'getFullPath' should be used.
$this->setFile ("my_file.txt"); $this->setDirTpl ("/path/to/file/"); ... $this->getFullPath (); // outputs '/path/to/file/my_file.txt', if file exists
Template Variables Template Variables are assigned keywords referencing a value determined by the program code. The assigned keys are paired with the Template file, replacing the 'keyword' with the value. Template Variables can be any type, however check the specific Engine on any restrictions defined.
$this->assign ("key", my_value); $this->key = my_value;
Delimeters This is simply a left and right character string surrounding keywords, helping to separate raw text. Inside a basic string replacement Engine, curly braces could surround the keyword '{keyword}' (or any other characters). The parser (if used) should find these replacements.
Author(s): |
Michael Luster <mluster79@yahoo.com> |
License: | New BSD License |
Copyright: | Copyright (c) 2007, iBayou, Michael Luster |
Link: | http://sourceforge.net/projects/phpgumbo |
Version: | 0.0.1 |
Implements interfaces:
Child classes:
Class Variables
Class Methods
Assigns a template variable with a value
Parameter(s):
- (string|array) $key :: template file reference
- (mixed) $val
- throws:
Gumbo_Exception Overridden in child classes as:
- Gumbo_Template_Engine_Basic::assign()
- Assigns a template variable with a value
[ Top ]public string fetch ( [bool $reload] ) [line 173]Returns the formatted template file string
Parameter(s):
- (bool) $reload :: parses the template file again
- precondition:
exists() - throws:
Gumbo_Exception
[ Top ]public mixed getVar ( string $key ) [line 550]Returns the value of the key reference
Parameter(s):
- (string) $key :: reference key
- throws:
Gumbo_Exception
[ Top ]public void loadGlobals ( [bool $assign_global_vars] ) [line 269]Loads the global template variables (does not load global Template variables)
Parameter(s):
- (bool) $assign_global_vars :: also assigns global variables
- throws:
Gumbo_Exception - uses:
Gumbo_Template
[ Top ]- precondition:
setOutput (null) - postcondition:
isFormatted () - precondition:
setFormatted (false) Overridden in child classes as:
- Gumbo_Template_Engine_Basic::parse()
- Parses the template file into an HTML string
- Gumbo_Template_Engine_Internal::parse()
- Parses the template file into an HTML string
[ Top ]public void reset ( ) [line 258]Resets the template variables (useful for reloading a List)
- postcondition:
!isFormatted() - postcondition:
!getVars()
[ Top ]public void setDirCache ( string $loc ) [line 370]Sets the template file cache directory
Parameter(s):
- (string) $loc
- precondition:
is_dir ($loc) - throws:
Gumbo_Exception
[ Top ]public void setDirCompile ( string $loc ) [line 346]Sets the template file compile directory
Parameter(s):
- (string) $loc
- precondition:
is_dir ($loc) - throws:
Gumbo_Exception
[ Top ]public void setDirConfig ( string $loc ) [line 394]Sets the template file config directory
Parameter(s):
- (string) $loc
- precondition:
is_dir ($loc) - throws:
Gumbo_Exception
[ Top ]public void setDirTpl ( string $loc ) [line 323]Sets the template file directory
Parameter(s):
- (string) $loc
- precondition:
is_dir ($loc) - throws:
Gumbo_Exception
[ Top ]public void setFile ( string $file ) [line 303]Sets the template file name
Parameter(s):
- (string) $file
[ Top ]protected void setFormatted ( bool $val ) [line 457]Sets the template file as formatted
Parameter(s):
- (bool) $val
- throws:
Gumbo_Exception
[ Top ]public void setLeftDelimeter ( string $val ) [line 417]Sets the left delimeter value
Parameter(s):
- (string) $val
- throws:
Gumbo_Exception
[ Top ]protected void setOutput ( string $output ) [line 476]Sets the formatted output template string
Parameter(s):
- (string) $output
- throws:
Gumbo_Exception
[ Top ]public void setRightDelimeter ( string $val ) [line 437]Sets the right delimeter value
Parameter(s):
- (string) $val
- throws:
Gumbo_Exception
[ Top ]public void unassign ( string $key ) [line 236]Unassigns a template variable
Parameter(s):
- (string) $key
- throws:
Gumbo_Exception
[ Top ]public mixed __get ( string $key ) [line 135]Returns the value of a template key reference
Parameter(s):
- (string) $key
[ Top ]public bool __isset ( string $key ) [line 144]Returns if the template reference key isset
Parameter(s):
- (string) $key
[ Top ]public void __set ( string $key, mixed $val ) [line 126]Assigns a template variable with a value
Parameter(s):
- (string) $key :: template file reference
- (mixed) $val :: primitive type or Gumbo_Interface_Output
[ Top ]