ILIAS
trunk Revision v11.0_alpha-1769-g99a433fe2dc
|
Integrated Template Extension - ITX With this class you get the full power of the phplib template class. More...
Public Member Functions | |
__construct (string $root='') | |
Builds some complex regexps and calls the constructor of the parent class. More... | |
replaceBlock (string $block, string $template, bool $keep_content=false) | |
Replaces an existing block with new content. More... | |
addBlock (string $placeholder, string $blockname, string $template) | |
Adds a block to the template changing a variable placeholder to a block placeholder. More... | |
addBlockfile (string $placeholder, string $blockname, string $filename) | |
Adds a block taken from a file to the template changing a variable placeholder to a block placeholder. More... | |
removeBlockData (string $block) | |
Recursively removes all data assiciated with a block, including all inner blocks. More... | |
blockExists (string $blockname) | |
Checks wheter a block exists. More... | |
buildFunctionlist () | |
Builds a functionlist from the template. More... | |
getValue (string $code, $delimiter) | |
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " or '. More... | |
deleteFromBlockvariablelist (string $block, $variables) | |
Deletes one or many variables from the block variable list. More... | |
updateBlockvariablelist (string $block) | |
Updates the variable list of a block. More... | |
findPlaceholderBlocks (string $variable) | |
Returns an array of blocknames where the given variable placeholder is used. More... | |
warning (string $message, string $file='', int $line=0) | |
Handles warnings, saves them to $warn and prints them or calls die() depending on the flags. More... | |
![]() | |
__construct (string $root='', ?array $options=null) | |
Builds some complex regular expressions and optinally sets the file root directory. More... | |
setOption (string $option, $value) | |
Sets the option for the template class. More... | |
setOptions (array $options) | |
Sets the options for the template class. More... | |
show (string $block=self::IT_DEFAULT_BLOCK) | |
Print a certain block with all replacements done. More... | |
get (string $block=self::IT_DEFAULT_BLOCK) | |
Returns a block with all replacements done. More... | |
parse (string $block=self::IT_DEFAULT_BLOCK, bool $flag_recursion=false) | |
Parses the given block. More... | |
parseCurrentBlock () | |
Parses the current block. More... | |
setVariable ($variable, $value='') | |
Sets a variable value. More... | |
setCurrentBlock (string $block=self::IT_DEFAULT_BLOCK) | |
Sets the name of the current block that is the block where variables are added. More... | |
touchBlock (string $block) | |
Preserves an empty block even if removeEmptyBlocks is true. More... | |
free () | |
Clears all datafields of the object. More... | |
setTemplate (string $template, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true) | |
Sets the template. More... | |
loadTemplatefile (string $filename, bool $removeUnknownVariables=true, bool $removeEmptyBlocks=true) | |
Reads a template file from the disk. More... | |
setRoot (string $root) | |
Sets the file root. More... | |
buildBlockvariablelist () | |
Build a list of all variables within of a block. More... | |
findBlocks (string $string) | |
Recusively builds a list of all blocks within the template. More... | |
getFile (string $filename) | |
Reads a file from disk and returns its content. More... | |
_addPregDelimiters (string $str) | |
Adds delimiters to a string, so it can be used as a pattern in preg_* functions. More... | |
_preserveOpeningDelimiter (string $str) | |
Replaces an opening delimiter by a special string. More... | |
errorMessage (int $value, string $blockname='') | |
Return a textual error message for a IT error code. More... | |
Data Fields | |
array | $warn = [] |
Array with all warnings. More... | |
bool | $printWarning = false |
Print warnings? More... | |
bool | $haltOnWarning = false |
Call die() on warning? More... | |
string | $checkblocknameRegExp = '' |
RegExp used to test for a valid blockname. More... | |
string | $functionPrefix = 'func_' |
Functionnameprefix used when searching function calls in the template. More... | |
string | $functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*' |
Functionname RegExp. More... | |
string | $functionRegExp = '' |
RegExp used to grep function calls in the template. More... | |
array | $functions = [] |
List of functions found in the template. More... | |
array | $callback = [] |
List of callback functions specified by the user. More... | |
![]() | |
const | IT_OK = 1 |
const | IT_ERROR = -1 |
const | IT_TPL_NOT_FOUND = -2 |
const | IT_BLOCK_NOT_FOUND = -3 |
const | IT_BLOCK_DUPLICATE = -4 |
const | IT_UNKNOWN_OPTION = -6 |
const | IT_DEFAULT_BLOCK = '__global__' |
array | $err = [] |
Contains the error objects. More... | |
bool | $clearCache = false |
Clear cache on get()? More... | |
string | $openingDelimiter = '{' |
First character of a variable placeholder ( _{_VARIABLE} ). More... | |
string | $closingDelimiter = '}' |
Last character of a variable placeholder ( {VARIABLE_}_ ). More... | |
string | $blocknameRegExp = '[\.0-9A-Za-z_-]+' |
RegExp matching a block in the template. More... | |
string | $variablenameRegExp = '[\.0-9A-Za-z_-]+' |
RegExp matching a variable placeholder in the template. More... | |
string | $variablesRegExp = '' |
RegExp used to find variable placeholder, filled by the constructor. More... | |
string | $removeVariablesRegExp = '' |
RegExp used to strip unused variable placeholder. More... | |
bool | $removeUnknownVariables = true |
Controls the handling of unknown variables, default is remove. More... | |
bool | $removeEmptyBlocks = true |
Controls the handling of empty blocks, default is remove. More... | |
string | $blockRegExp = '' |
RegExp used to find blocks an their content, filled by the constructor. More... | |
string | $currentBlock = self::IT_DEFAULT_BLOCK |
Name of the current block. More... | |
string | $template = '' |
Content of the template. More... | |
array | $blocklist = [] |
Array of all blocks and their content. More... | |
array | $blockdata = [] |
Array with the parsed content of a block. More... | |
array | $blockvariables = [] |
Array of variables in a block. More... | |
array | $blockparents = [] |
Array of block parents. More... | |
array | $blockinner = [] |
Array of inner blocks of a block. More... | |
array | $touchedBlocks = [] |
List of blocks to preverse even if they are "empty". More... | |
array | $variableCache = [] |
Variable cache. More... | |
bool | $clearCacheOnParse = false |
Clear the variable cache on parse? If you're not an expert just leave the default false. More... | |
string | $fileRoot = '' |
Root directory for all file operations. More... | |
bool | $flagBlocktrouble = false |
Internal flag indicating that a blockname was used multiple times. More... | |
bool | $flagGlobalParsed = false |
Flag indicating that the global block was parsed. More... | |
bool | $flagCacheTemplatefile = true |
EXPERIMENTAL! FIXME! Flag indication that a template gets cached. More... | |
string | $lastTemplatefile = '' |
EXPERIMENTAL! FIXME! More... | |
array | $_options |
$_options['preserve_data'] Whether to substitute variables and remove empty placeholders in data passed through setVariable (see also bugs #20199, #21951). More... | |
Protected Member Functions | |
init () | |
![]() | |
init () | |
Clears all datafields of the object and rebuild the internal blocklist LoadTemplatefile() and setTemplate() automatically call this function when a new template is given. More... | |
Additional Inherited Members | |
![]() | |
array string | $real_filename = '' |
Holds the real template file name. More... | |
Integrated Template Extension - ITX With this class you get the full power of the phplib template class.
You may have one file with blocks in it but you have as well one main file and multiple files one for each block. This is quite usefull when you have user configurable websites. Using blocks not in the main template allows you to modify some parts of your layout easily. Note that you can replace an existing block and add new blocks at runtime. Adding new blocks means changing a variable placeholder to a block.
HTML_Template_ITX::__construct | ( | string | $root = '' | ) |
Builds some complex regexps and calls the constructor of the parent class.
Make sure that you call this constructor if you derive your own template class from this one.
ilTemplateException |
Definition at line 99 of file ITX.php.
References ILIAS\GlobalScreen\Provider\__construct().
HTML_Template_ITX::addBlock | ( | string | $placeholder, |
string | $blockname, | ||
string | $template | ||
) |
Adds a block to the template changing a variable placeholder to a block placeholder.
Add means "replace a variable placeholder by a new block". This is different to PHPLibs templates. The function loads a block, creates a handle for it and assigns it to a certain variable placeholder. To to the same with PHPLibs templates you would call set_file() to create the handle and parse() to assign the parsed block to a variable. By this PHPLibs templates assume that you tend to assign a block to more than one one placeholder. To assign a parsed block to more than only the placeholder you specify in this function you have to use a combination of getBlock() and setVariable(). As no updates to cached data is necessary addBlock() and addBlockfile() are rather "cheap" meaning quick operations. The block content must not start with and end with this would cause overhead and produce an error.
ilTemplateException |
Definition at line 186 of file ITX.php.
References deleteFromBlockvariablelist(), HTML_Template_IT\findBlocks(), findPlaceholderBlocks(), and updateBlockvariablelist().
Referenced by ilTemplate\addBlockFile(), and addBlockfile().
HTML_Template_ITX::addBlockfile | ( | string | $placeholder, |
string | $blockname, | ||
string | $filename | ||
) |
Adds a block taken from a file to the template changing a variable placeholder to a block placeholder.
ilTemplateException |
Definition at line 248 of file ITX.php.
References addBlock(), and HTML_Template_IT\getFile().
HTML_Template_ITX::blockExists | ( | string | $blockname | ) |
HTML_Template_ITX::buildFunctionlist | ( | ) |
Builds a functionlist from the template.
Definition at line 285 of file ITX.php.
References HTML_Template_IT\$closingDelimiter, HTML_Template_IT\$template, and getValue().
Referenced by ilTemplate\init(), and init().
HTML_Template_ITX::deleteFromBlockvariablelist | ( | string | $block, |
$variables | |||
) |
Deletes one or many variables from the block variable list.
array | string | $variables | Name of one variable or array of variables ( array ( name => true ) ) to be stripped. |
Definition at line 377 of file ITX.php.
Referenced by addBlock().
HTML_Template_ITX::findPlaceholderBlocks | ( | string | $variable | ) |
Returns an array of blocknames where the given variable placeholder is used.
Definition at line 429 of file ITX.php.
Referenced by addBlock().
HTML_Template_ITX::getValue | ( | string | $code, |
$delimiter | |||
) |
Truncates the given code from the first occurence of $delimiter but ignores $delimiter enclosed by " or '.
array | string | $delimiter |
Definition at line 330 of file ITX.php.
Referenced by buildFunctionlist().
|
protected |
Definition at line 108 of file ITX.php.
References HTML_Template_IT\buildBlockvariablelist(), buildFunctionlist(), HTML_Template_IT\findBlocks(), and HTML_Template_IT\free().
HTML_Template_ITX::removeBlockData | ( | string | $block | ) |
Recursively removes all data assiciated with a block, including all inner blocks.
Definition at line 256 of file ITX.php.
Referenced by replaceBlock().
HTML_Template_ITX::replaceBlock | ( | string | $block, |
string | $template, | ||
bool | $keep_content = false |
||
) |
Replaces an existing block with new content.
This function will replace a block of the template and all blocks contained in the replaced block and add a new block insted, means you can dynamically change your template. Note that changing the template structure violates one of the IT[X] development goals. I've tried to write a simple to use template engine supporting blocks. In contrast to other systems IT[X] analyses the way you've nested blocks and knows which block belongs into another block. The nesting information helps to make the API short and simple. Replacing blocks does not only mean that IT[X] has to update the nesting information (relatively time consumpting task) but you have to make sure that you do not get confused due to the template change itself.
bool | $keep_content | true if the new block inherits the content of the old block |
ilTemplateException |
Definition at line 134 of file ITX.php.
References HTML_Template_IT\$blockdata, HTML_Template_IT\buildBlockvariablelist(), HTML_Template_IT\findBlocks(), and removeBlockData().
HTML_Template_ITX::updateBlockvariablelist | ( | string | $block | ) |
Updates the variable list of a block.
Definition at line 394 of file ITX.php.
Referenced by addBlock().
HTML_Template_ITX::warning | ( | string | $message, |
string | $file = '' , |
||
int | $line = 0 |
||
) |
array HTML_Template_ITX::$callback = [] |
string HTML_Template_ITX::$checkblocknameRegExp = '' |
string HTML_Template_ITX::$functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*' |
string HTML_Template_ITX::$functionPrefix = 'func_' |
string HTML_Template_ITX::$functionRegExp = '' |
array HTML_Template_ITX::$functions = [] |
bool HTML_Template_ITX::$haltOnWarning = false |
bool HTML_Template_ITX::$printWarning = false |