Class: HTML_Template_Sigma
Source Location: /HTML_Template_Sigma-1.2.0/Sigma.php
PEAR
|
--HTML_Template_Sigma
Implementation of Integrated Templates API with template 'compilation' added.
Author(s):
Version:
|
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
Class Variables
Method Detail
HTML_Template_Sigma (Constructor) [line 379]
HTML_Template_Sigma HTML_Template_Sigma(
[string
$root = ''], [string
$cacheRoot = ''])
|
|
Constructor: builds some complex regular expressions and optionally sets the root directories. Make sure that you call this constructor if you derive your template class from this one.
Parameters:
addBlock [line 911]
mixed addBlock(
string
$placeholder, string
$block, string
$template)
|
|
Adds a block to the template changing a variable placeholder to a block placeholder. This means that a new block will be integrated into the template in place of a variable placeholder. The variable placeholder will be removed and the new block will behave in the same way as if it was inside the original template. The block content must not start with <!-- BEGIN blockname --> and end with <!-- END blockname -->, if it does the error will be thrown.
Parameters:
addBlockfile [line 948]
mixed addBlockfile(
string
$placeholder, string
$block, string
$filename)
|
|
Adds a block taken from a file to the template, changing a variable placeholder to a block placeholder.
Parameters:
blockExists [line 1049]
bool blockExists(
string
$block)
|
|
Checks if the block exists in the template
Parameters:
clearVariables [line 1207]
Clears the variables Global variables are not affected. The method is useful when you add a lot of variables via setVariable() and are not sure whether all of them appear in the block you parse(). If you clear the variables after parse(), you don't risk them suddenly showing up in other blocks.
errorMessage [line 479]
string errorMessage(
integer
$code, [string
$data = null])
|
|
Returns a textual error message for an error code
Parameters:
get [line 533]
string get(
[string
$block = '__global__'], [bool
$clear = false])
|
|
Returns a block with all replacements done.
Parameters:
getBlockList [line 1151]
array getBlockList(
[string
$parent = '__global__'], [bool
$recursive = false])
|
|
Returns a list of blocks within a template. If $recursive is false, it returns just a 'flat' array of $parent's direct subblocks. If $recursive is true, it builds a tree of template blocks using $parent as root. Tree structure is compatible with PEAR::Tree's Memory_Array driver.
Parameters:
getCurrentBlock [line 756]
string getCurrentBlock(
)
|
|
Returns the current block name
getPlaceholderList [line 1181]
array getPlaceholderList(
[string
$block = '__global__'])
|
|
Returns a list of placeholders within a block. Only 'normal' placeholders are returned, not auto-created ones.
Parameters:
hideBlock [line 816]
mixed hideBlock(
string
$block)
|
|
Hides the block even if it is not "empty". Is somewhat an opposite to touchBlock(). Consider a block (a 'edit' link for example) that should be visible to registered/"special" users only, but its visibility is triggered by some little 'id' field passed in a large array into setVariable(). You can either carefully juggle your variables to prevent the block from appearing (a fragile solution) or simply call hideBlock()
Parameters:
loadTemplateFile [line 872]
mixed loadTemplateFile(
string
$filename, [boolean
$removeUnknownVariables = true], [boolean
$removeEmptyBlocks = true])
|
|
Loads a template file. If caching is on, then it checks whether a "prepared" template exists. If it does, it gets loaded instead of the original, if it does not, then the original gets loaded and prepared and then the prepared version is saved. addBlockfile() and replaceBlockfile() implement quite the same logic.
Parameters:
parse [line 571]
void parse(
[string
$block = '__global__'], [boolean
$flagRecursion = false], [boolean
$fakeParse = false])
|
|
Parses the given block.
Parameters:
parseCurrentBlock [line 744]
void parseCurrentBlock(
)
|
|
Parses the current block
placeholderExists [line 1065]
string placeholderExists(
string
$placeholder, [string
$block = ''])
|
|
Returns the name of the (first) block that contains the specified placeholder.
Parameters:
replaceBlock [line 988]
mixed replaceBlock(
string
$block, string
$template, [boolean
$keepContent = false])
|
|
Replaces an existing block with new content. This function will replace a block of the template and all blocks contained in it and add a new block instead. This means you can dynamically change your template. Sigma analyses the way you've nested blocks and knows which block belongs into another block. This nesting information helps to make the API short and simple. Replacing blocks does not only mean that Sigma has to update the nesting information (relatively time consuming task) but you have to make sure that you do not get confused due to the template change yourself.
Parameters:
replaceBlockfile [line 1020]
mixed replaceBlockfile(
string
$block, string
$filename, [boolean
$keepContent = false])
|
|
Replaces an existing block with new content from a file.
Parameters:
setCacheRoot [line 433]
void setCacheRoot(
string
$root)
|
|
Sets the directory to cache "prepared" templates in, the directory should be writable for PHP. The "prepared" template contains an internal representation of template structure: essentially a serialized array of $_blocks, $_blockVariables, $_children and $_functions, may also contain $_triggers. This allows to bypass expensive calls to _buildBlockVariables() and especially _buildBlocks() when reading the "prepared" template instead of the "source" one. The files in this cache do not have any TTL and are regenerated when the source templates change.
Parameters:
setCallbackFunction [line 1124]
mixed setCallbackFunction(
string
$tplFunction, mixed
$callback, [bool
$preserveArgs = false])
|
|
Sets a callback function. Sigma templates can contain simple function calls. This means that the author of the template can add a special placeholder to it: func_h1("embedded in h1") Sigma will parse the template for these placeholders and will allow you to define a callback function for them. Callback will be called automatically when the block containing such function call is parse()'d. Please note that arguments to these template functions can contain variable placeholders: func_translate('Hello, {username}'), but not blocks or other function calls. This should NOT be used to add logic (except some presentation one) to the template. If you use a lot of such callbacks and implement business logic through them, then you're reinventing the wheel. Consider using XML/XSLT, native PHP or some other template engine. function h_one($arg) {
return '<h1>' . $arg . '</h1>';
}
...
...
template: func_h1('H1 Headline');
Parameters:
setCurrentBlock [line 728]
mixed setCurrentBlock(
[string
$block = '__global__'])
|
|
Sets the name of the current block: the block where variables are added
Parameters:
setGlobalVariable [line 708]
void setGlobalVariable(
mixed
$variable, [string
$value = ''])
|
|
Sets a global variable value.
Parameters:
setOption [line 461]
mixed setOption(
string
$option, mixed
$value)
|
|
Sets the option for the template class Currently available options: - preserve_data: If false (default), then substitute variables and
remove empty placeholders in data passed through setVariable (see also
PHP bugs #20199, #21951)
- trim_on_save: Whether to trim extra whitespace from template on cache
save (defaults to true). Generally safe to leave this on, unless you
have <pre></pre> in templates or want to preserve HTML indentantion
- charset: is used by builtin template callback 'h'/'e'. Defaults to 'iso-8859-1'
Parameters:
setRoot [line 407]
void setRoot(
string
$root)
|
|
Sets the file root for templates. The file root gets prefixed to all filenames passed to the object.
Parameters:
setTemplate [line 842]
mixed setTemplate(
string
$template, [boolean
$removeUnknownVariables = true], [boolean
$removeEmptyBlocks = true])
|
|
Sets the template. You can either load a template file from disk with LoadTemplatefile() or set the template manually using this function.
Parameters:
setVariable [line 688]
void setVariable(
mixed
$variable, [string
$value = ''])
|
|
Sets a variable value. The function can be used either like setVariable("varname", "value") or with one array $variables["varname"] = "value" given setVariable($variables)
Parameters:
show [line 517]
void show(
[string
$block = '__global__'])
|
|
Prints a block with all replacements done.
Parameters:
touchBlock [line 787]
mixed touchBlock(
string
$block)
|
|
Preserves the block even if empty blocks should be removed. Sometimes you have blocks that should be preserved although they are empty (no placeholder replaced). Think of a shopping basket. If it's empty you have to show a message to the user. If it's filled you have to show the contents of the shopping basket. Now where to place the message that the basket is empty? It's not a good idea to place it in you application as customers tend to like unecessary minor text changes. Having another template file for an empty basket means that one fine day the filled and empty basket templates will have different layouts. So blocks that do not contain any placeholders but only messages like "Your shopping basked is empty" are intoduced. Now if there is no replacement done in such a block the block will be recognized as "empty" and by default ($removeEmptyBlocks = true) be stripped off. To avoid this you can call touchBlock()
Parameters:
Documentation generated on Tue, 22 Jul 2008 15:30:08 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|
|