I've been really interested in a true templating system for some time now, such things as "headers" and "footers" really arn't my thing... So I've decided to get my head down and code one.
Basically, what I plan to do is create a phraser... "index.php"... which works like your average templating system... e.g. index.php?page=/chat/signup.php etc...
BUT, this one will then check the users MySQL table to fetch the theme, (e.g. chromonoma.tpl - don't ask
e.g. For the news posting... Lots of global variables are set, like {news_author}, {news_post_size}, {news_post_date} etc.
Then, the designer can make several themes placing the certain variables where he wishes... and surrounding them in some type of logic... ({while news top 10} etc).
Of course, it'll be compressed output, cached and blah blah blah... I'm just wondering if anyone has any feedback, any past TRUE examples of this type... anyone made anything like this that they haven't yet shared out ? If so, please say if you wish to trade some "notes" (FULL LENGTH CODE
Well... I hope I've been annoying enough for my first post... what 'ya recon', 7 outta' 10? 9? WOW... Geeeeeeee THNX! :S
P.S... this is something I'm working on, it's not related DIRECTLY to this, but I dunno... maybe someone will follow my logic....
Code: Select all
<?php
$fp = fopen("./templates/news/display.tpl", "r");
$contents = fread($fp, filesize("./templates/news/display.tpl"));
fclose($fp);
preg_match_all("/\{.*?\}/s", $contents, $variable_match);
foreach($variable_matchї0] as $variable) {
$parts = explode(" ", substr($variable, 1, -1));
if ($partsї0] == "if") {
$reply = "<?php if (" . $partsї1] . " " . $partsї2] . " " . $partsї3] . ") { ?>";
} elseif ($partsї0] == "elseif") {
$reply = "<?php } elseif (" . $partsї1] . " " . $partsї2] . " " . $partsї3] . ") { ?>";
} elseif ($partsї0] == "else") {
$reply = "<?php } else { ?>";
} elseif ($partsї0] == "/if") {
$reply = "<?php } ?>";
} else {
$reply = "<?php echo ($" . "resultsї"" . $partsї0] . ""]); ?>";
}
$contents = str_replace($variable, $reply, $contents);
}
$fp = fopen("./templates/news/display.php", "w");
fputs($fp, $contents);
fclose($fp);
?>