Source for file Generator.php
Documentation is available at Generator.php
require_once 'HTML/Template/PHPLIB/Helper.php';
* Generates code to be used with templates
* @package HTML_Template_PHPLIB
* @author Christian Weiske <cweiske@php.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear.php.net/package/HTML_Template_PHPLIB
* Creates the code to use a given template file
* @param string $strFile Template file
* @param string $strTplName Template reference name
* @param string $strPrefix Prefix to prepend before the code
* @return string PHP code
if ($strTplName === null ) {
$code .= $strPrefix . ' = new HTML_Template_PHPLIB();' . $nl;
$code .= '//TODO: do something with the code' . $nl;
$code .= $strPrefix . '->finish('
. trim($strPrefix) . "->parse('TMP', '" . $strTplName . "'));" . $nl;
}//function getCodeBlockDefinition($strFile, $strTplName = null, $strPrefix = '$tpl')
* Creates the PHP code for the given array of blocks.
* @param array $arBlocks Array of blocks, see getBlocks()
* @param string $strTplName Template reference name
* @param string $strPrefix Prefix to prepend before the code
* @return string PHP code
function getCodeBlock($arBlocks, $strTplName, $strPrefix = '$tpl')
foreach ($arBlocks as $arBlock) {
if (count($arBlock['sub']) > 0 ) {
$arBlock['sub'], $strTplName, $strPrefix
$code .= $strPrefix . "->setBlock('" . $strTplName . "','"
. $arBlock['name'] . "', '"
. $arBlock['name'] . "_ref');" . $nl;
}//function getCodeBlock($arBlocks, $strTplName, $strPrefix = '$tpl')
* Returns an array of blocks in the given template code.
* The array values are array with a key "name" and
* "sub", an array of nested blocks.
* @param array $arLines Template code lines
* @return array Array of blocks
$strRegex = '/<!--\s+(BEGIN|END)\s+([a-zA-Z0-9_]*)\s+-->/';
foreach ($arLines as $nLine => $strLine) {
if (!preg_match($strRegex, $strLine, $arMatches)) {
$strType = $arMatches[1 ];
$strBlockName = $arMatches[2 ];
if ($strType == 'BEGIN') {
if (count($arRefs) == 0 ) {
$arBlocks[$arBlock['name']] = $arBlock;
$arRefs[$strBlockName] = &$arBlocks[$arBlock['name']];
$strOldBlock = key($arRefs);
$arRefs[$strOldBlock]['sub'][$strBlockName] = $arBlock;
$arRefs[$strBlockName] = & $arRefs[$strOldBlock]['sub'][$strBlockName];
unset ($arRefs[$strBlockName]);
}//function getBlocks($arLines)
* Creates a name that can be used as handle for a template,
* from the given file name.
* @param string $strFile File name
* @return string Template name
$nDotPos = strpos($strTplName, '.');
if ($nDotPos !== false ) {
$strTplName = substr($strTplName, 0 , $nDotPos);
}//function getTemplateNameFromFilename($strFile)
}//class HTML_Template_PHPLIB_Generator
Documentation generated on Mon, 11 Mar 2019 15:10:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|