Menu

#6 Includes

open
nobody
None
5
2008-12-17
2008-12-17
Anonymous
No

/**
* processes template
*
* @return void
*/
protected function parse() {
$this->_template = $this->substituteLoops($this->_template, $this->_content);
$this->_template = $this->substituteContentTags($this->_template, $this->_content);
$this->_template = $this->substituteIncludes($this->_template, $this->_content); // NEW LINE
$this->_parsed = TRUE;
}
/**
* substitutes includes in string with content
*
* @return string
* @param string $string
* @param array $content
*/
protected function substituteIncludes($string, $content) {
$this->_tempContent = $content;
return preg_replace_callback('/(include|include_once|require|require_once)[ ]?[\"\'](.*)[\"\'][;]?/i', array($this, 'getContentOfIncludeTag'), $string);
}
/**
* substitutes includes in string with content
*
* @return string
* @param string $string
* @param array $content
*/
protected function getContentOfIncludeTag($includeName) {
$file = $includeName[2];
if(file_exists($file)) {
$fp = fopen($file, "rb");
$returnValue = fread($fp, filesize($file));
fclose($fp);
} else {
$returnValue = '[ERROR: The file "'.$file.'" could not be included!]';
}
return $returnValue;
}

TPL:

include 'einzubinden.txt';

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.