12-28-2008, 10:44 PM
|
#4 (permalink)
|
|
The Wanderer
Join Date: Dec 2008
Posts: 16
Thanks: 2
|
Hello,
Thank you for your reply's why i do not want to use a premade template system is i am trying to make my own sort of framework that ill use for all my projects. I would like it to be set out like this i know it mite be a bit slower but it does not bother me a lot here is what i have worked out so far but i am unsure again if this would be on the right track.
PHP Code:
<?php
class template { var $template_dir = '.templates/'; var $file_ext = '.tpl'; var $buffer; function buff_template ($file) { if( file_exists( $this->template_dir . $file . $this->file_ext ) ) { $this->buffer = file_get_contents( $this->template_dir . $file . $this->file_ext ); return $this->parse_variables($this->buffer); } else { die(); } } function parse_variables($input) { $search = preg_match_all('/<-- {.*?} -->/', $input, $matches); foreach($matches as $value) { $input = preg_replace("'<-- if (.*) -->'","<? if(\\1) {?>", $input); $input = preg_replace("'<-- foreach (.*) -->'","<? foreach(\\1) {?>", $input); } $content = str_replace("<-- endif -->","<?}?>", $content); $content = str_replace("<-- endforeach -->","<?}?>", $content); return $input; }
}
$engine = new template;
echo eval("?>$engine->buff_template(login)<?"); ?>
|
|
|
|