Plik przed sparsowaniem z rozszerzeniem TPL
<!DOCTYPE html>
[if $a==1]{title}[/if][else]Brak[/else]
Plik po sparsowaniu z rozszerzeniem PHP
<!DOCTYPE html>
<head>
<title>Tytuł</title>
</head>
<body>
<?php if ($a==1
) { echo "Tytuł"; } else { echo "Brak"; } ?> </body>
</html>
Teraz mam pytanie czemu to nie działa, tzn. nic oprócz Tytułu w tagu <title></title> się nie wyświetla ?
Kod Parsera
<?php
class Template
{
var $TemplateDir = "themes/default";
var $CacheDir = "cache";
(
"#\[b\](.*?)\[/b\]#" => "<strong>\\1</strong>",
"#\[if (.*?)\](.*?)\[/if\]#" => "<?php if (\\1) { echo \"\\2\"; } ?>"
);
function Template($filename)
{
$this->baseDir = $this->TemplateDir;
$this->cacheDir = $this->CacheDir;
$this->fileTemplateExt = $filename.".tpl";
$this->fileCacheExt = $filename.".php";
$this->fileTemplate = $this->baseDir."/".$this->fileTemplateExt;
$this->fileCache = $this->cacheDir."/".$this->fileCacheExt;
}
function LoadTemplate()
{
{
die("File not found: ".$this->fileTemplate." !"); }
foreach($this->code as $source => $destination)
{
$this->template = preg_replace($source, $destination, $this->template); }
}
function Replacer($name, $value)
{
$this->template = str_replace("{".$name."}", $value, $this->template); }
function Show()
{
if(!$this->Exists())
{
$this->Save($this->template);
return $this->Load();
}
else
{
return $this->Load();
}
}
function Exists()
{
}
function Save($data)
{
$fp = fopen($this->fileCache, "w"); }
function Load()
{
}
}
?>