//Author Helio 01/27/09
//plugin to load a template from the file system
$e = & $modx->Event;
switch($e->name){
case 'OnLoadWebDocument':
$tplContent = $modx->documentContent;
if( substr($tplContent,0,6) == "@FILE:"){
$templatePath = substr($tplContent,6);
$toFile = $modx->config['base_path'] ."assets/templates/".trim($templatePath);
if(is_file($toFile)){
//Start the buffer
ob_start();
include $toFile;
//get contents from the buffer
$ob_contents = ob_get_contents();
//and kill/delete the buffer
ob_end_clean();
//return it to MODx
$modx->documentContent = $ob_contents;
}else{
$modx->documentContent = "Erreur lors du chargement du template => ".$toFile;
}
}
break;
default:
break;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Post reply" /> <meta name="keywords" content="MODx, PHP, application, framework, CMS, content, management, system, web, 2.0, ajax, open, source" /> <meta name="robots" content="index,follow" /> @FILE:myfolderTemplate/index.html <div id="footer"> some footer here </div>
@FILE:myfolderTemplate/header.html @FILE:myfolderTemplate/body.html @FILE:myfolderTemplate/footer.html

$basefolder = (isset($basefolder)) ? $basefolder : $modx->config['base_path'] ."assets/templates/"; //not yet supported
$pattern = "~@FILE:(.*)~";
$e = & $modx->Event;
switch($e->name){
case 'OnLoadWebDocument':
$tplContent = $modx->documentContent;
$modx->documentContent = parseExternalTpl($pattern,$tplContent,$basefolder);
break;
default:
break;
}
function parseExternalTpl($pattern,$tplContent,$basePath){
if(preg_match_all($pattern,$tplContent,$matches)){
$tot = count($matches[0]);
for($i=0;$i<$tot;$i++){
$result[$matches[0][$i]] = parseExternalTpl($pattern,loadExternalContent($basePath,$matches[1][$i]),$basePath);
}
$output = str_replace(array_keys($result),array_values($result),$tplContent);
}else{
$output = $tplContent;
}
return $output;
}
function loadExternalContent($basePath,$fileName){
$toFile = $basePath.trim($fileName);
if(is_file($toFile)){
//Start the buffer
ob_start();
include $toFile;
//get contents from the buffer
$ob_contents = ob_get_contents();
//and kill/delete the buffer
ob_end_clean();
}else{
$ob_contents = "Erreur lors du chargement du template => ".$toFile;
}
return $ob_contents;
}
@FILE:header.tpl
@FILE:content.tpl
@FILE:footer.tpl
@FILE:main.tpl
@FILE:left.tpl
@FILE:right.tpl