What does your template engine do?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

What does your template engine do?

Post 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. :P

Complaints are welcome as well. :)

Cheers,
Alex
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: What does your template engine do?

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: What does your template engine do?

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: What does your template engine do?

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: What does your template engine do?

Post 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.
Post Reply