Page 1 of 1
What does your template engine do?
Posted: Fri Dec 26, 2008 5:17 am
by alex.barylski
I used Smarty when I first discovered it and since then never touched it again, favouring alternative syntax ever since. Lately however I have been seeing some hackish looking code and mild duplication in my templates which I know I could eliminate with a custom template engine.
Little things, like restricting myself to certain functions and not cheating by calling a model method directly from inside the template or perhaps checking GPC value directly using super globals. They are mostly eye sores but I hate them with a passion.
There are few more reasons I am strongly considering implementing a simple template engine, but...
I would like to hear you reasons/arguments for using Smarty or other template engine.
I have heard it all but incase I haven't lets hear em' again and see what happens.
Complaints are welcome as well.
Cheers,
Alex
Re: What does your template engine do?
Posted: Fri Dec 26, 2008 7:28 am
by jaoudestudios
I believe frameworks like Smarty, Zend, Cake etc are good, they enforce the MVC model and once familiar with the framework allow for rapid development. However, I do feel they are inefficient with a much larger overhead. So I think it depends on the project.
Re: What does your template engine do?
Posted: Fri Dec 26, 2008 7:47 am
by alex.barylski
Hmmm...
I was looking more for specifics on what you expect form a template engine/layer not a framework, like Zend. Personally I do not consider Smarty to be a framework, more a library that assists in enforcing a separation of very important layers.
I dislike (personally) when template engines offer caching. I htink that is best left to the client to decide (DB, RAM, File, etc) also handling when and why.
Looking at Smarty, they have some neat ideas with modifiers...but some of them go beyond the scope of what a modifiers should do. Actually a lot do.
Answering questions specific to the design of template engines...what questions would you ask and what answers would you give, if you were asked?
Ignoring the obvious like performance, bloat, etc.
Re: What does your template engine do?
Posted: Sun Dec 28, 2008 4:31 pm
by josh
I think there is a confusion surrounding the whole "template engine". Do you mean the "view" in MVC or do you mean a grammatical syntactic restriction you're going to place upon yourself within the said 'view'. I use an MVC framework and then use full PHP for the language. I can also hack my MVC framework to support smarty templates side by side with normal phtml templates at the same time.
If you need your templates to have "steroids" I'd just extend the view, similar to how jquery extends javascript, it adds on to it's capabilities without destroying all design that the langauge designers put into the language for you, which is what smarty does.
Re: What does your template engine do?
Posted: Sun Dec 28, 2008 5:08 pm
by alex.barylski
Do you mean the "view" in MVC or do you mean a grammatical syntactic restriction you're going to place upon yourself within the said 'view'.
Good point. Personally when I refer to template engine I refer to an system similar to Smarty.
My views are objects which use the template engine which then loads the template.
If you need your templates to have "steroids" I'd just extend the view, similar to how jquery extends javascript, it adds on to it's capabilities without destroying all design that the langauge designers put into the language for you, which is what smarty does.
My idea of a solid template engine is actually the opposite. using alternative syntax is powerful but perhaps a little to powerful. I am implementing a template engine to essentially prevent me from cheating or hacking and making template more prone to bad design.
For example, I have occassionally pulled on a model method inside a template or generated a list of items from a GLOBAL. I personally consider that a horrible practice, and I hate having that dependenciy in my template layer, so a template engine would prevent me from doing so, by offering a limited/subset version of the full imperative support provided by PHP.