![]() |
Template System
Hello,
I need some help i have been trying to make a template system but i am unsure on how to do it. Like it will read all the content of a file and replace seleted things with php if,foreach etc. EG of what i mean .tpl file HTML Code:
<-- if $member->group == admin --> |
A regex driven engine is pretty tough to make, and also is pretty slow than for instance, a php implementation of a templating system (php embedded templates). Besides of that, it also implies that you learn a new language, in between html and php. That can't be efficient. Why not use an existing templating system (like smarty, although I'm not a fan) and take a good look on how that was built.
|
I would recomend PHPTAL instead of Smarty.
|
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:
|
why not just use PHP?
PHP Code:
|
Quote:
PHP Code:
|
Thank you sketchMedia,
Ill use this that i did not know you could use endforeach; and endif; |
That's what I was recommending as well. Plus, by using directly PHP you also have all the language structures that PHP provides you: like initializing objects, calling they're methods, looping structures, and so on. That is:
1. hard to accomplish using another meta language for your templates 2. uselessly slow (I'm not talking about 1 template file with 100 lines. what do you do when you combine 7 different template files to make one big template, and then parse that (which let's say has 3000 lines). believe me, you will notice a decrease in performance there). you don't have to transform the php code to another language just so that you can transform it back into php later. I once tried to make a templating system myself, and finally got back to using php templates because of all the stuff that needed replication (like an if-else statement, or a while loop). ChrisR: that's the "long form" of the for, foreach, while, switch. |
Actually Xenon, a lot of PHP templating libraries compile the templates, so you will only suffer a performance hit on the initial page load.
There's no overhead most of the time and they are usually easier for designers to use as they don't need to learn how to use all PHP functions. |
| All times are GMT. The time now is 09:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0