Dat ligt aan welke template-parser je gebruikt
Maar als je zonder template-parser werkt, is beste om de PHP-als eerste uit te voeren. En alles wat in je HTML maar ge-cho'ed moet worden, in het begin al te defineren in een variabele
dit is geen template voor mij maar gewoon php file nu wat ik template noem is
<!DOCTYPE html>
<html lang="%locale->value%">
<head>
<title>%title->value%</title>
<meta charset="UTF-8">
<script type="text/javascript" src="%path.layout->value%js/wa.ajax"></script>
<link rel="stylesheet" type="text/css" href="%path.layout->value%bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="%path.layout->value%Xdebug.css">
<link rel="SHORTCUT ICON" href="%path.layout->value%logo.ico">
<link rel="stylesheet" type="text/css" href="%path.layout->value%%basic.css->value%">
<link rel="stylesheet" type="text/css" href="%path.layout->value%style.css">
<link rel="stylesheet" type="text/css" href="%path.layout->value%specials.css">
<link rel="stylesheet" type="text/css" href="%path.layout->value%constantes.css">
<meta name="robots" content="index, follow">
<meta name="googlebot" content="index,follow,archive" />
<meta name="keywords" content="%keywords->value%" >
<link rel="canonical" href="%URL_SELF->value%"/>
%location.css->value%
<script type="text/javascript" src="%path.layout->value%jquery/jquery.min.js"></script>
<script type="text/javascript" src="%path.layout->value%bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div id="topimg"><!----%title->value%--></div>
<header id="tophead">
<nav id="myNavbar" class="%collapse->value%">
<ul>
%nav->value%
</ul>
</nav>
%menutypes->value%
%find->value%
<div id="langbar" >
<a data-toggle="collapse" data-target="#myNavbar,#flags"><img class="icon" src="%path.layout->value%img/icons/m/menu.svg" alt="%collapse%"></a>
</div>
</header>
<section id="container">
<!--article id="content"-->
<a class="mysqlitem %row->value% col-xs-12" href="./?view=%help_topic_id->value%">
<span class="col-lg-8 col-md-8 col-sm-9 col-xs-9">
<p class="attention">%parentcategoryname->value%|%categoryname->value% </p>
<p> %name->value% </p>
<span class=" col-sm-10 hidden-xs">*</span>
</span>
</a>
de code zit iets complexer dan afgebeeld maar het is het idee dat telt (om niet met vertalingen en cach en clonen af te komen en het een beetje eenvoudig te houden)
PHP:
$x = $this->cancreatetemplate;
$view = Properties::get_Qtemplate($location,$name,$x);
preg_match_all('|'.$this->delimiter.'(.*)'.$this->delimiter.'|',$view,$keys);
$keys=$this->array_keyfinder($keys[1]);
$this->template = new Qtemplate($view);
$this->template->translate($this->translatekeys($keys));
if($this->cachIT){
$html=$this->template->gethtml();
$this->makecach($location,$name,$html);
}
}
$values['i'] = ++$this->i;
array_pop($path);
$values['path.layout']=$this->getLayoutPath();
$values['path.module']=$this->locationpath;
$this->template->setvalues($values);
return $this->template->gethtml();
<?php
/**
* @copyright 2009
* @CMS autosite
*/
class Qtemplate{
private $template;
private $html;
private $taglist=array();
private $htmltag;
private $tagnotfound=array();
private $toolsbar='';
private $y=0;
/**
* @param var $html
*/
function __construct(&$html){ $this->html=$html; }
public function reset($html){ $this->html=$html; }
/**
* @onerror if an error array to string convertion yo can give any array to the $value
* @param mixed $key
* @param mixed $value
* @return
*/
function toreplace($key,$value){
$this->html=str_replace('%'.$key.'%',$value,$this->html);
}
public function translate($asoarr){
if(!is_array($asoarr)){return; }
foreach($asoarr as $key => $value){
if($key!='toolbar'){
if ($value !=' '){ $this->toreplace($key,$value); }
}else{ $this->toreplace($key,$this->toolsbar); }
}
}
function settoolbar($toolbar,$link){ $this->toolsbar=$toolbar; }
public function setvalues($asoarr){
if(is_array($asoarr)){
foreach ($asoarr as $key=>$value){ $this->toreplace($key.'->value',$value); }
}
}
/**
* @return translated data
*/
public function gethtml(){
return $this->html;
}
}
?>