Template Engine

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Template Engine

Post by anthony88guy »

I've never used a Template Engine for my projects but I've worked with some. I'm interested in working with Smarty, but is it possible with a shared host?

If you view the Smarty quick install guide it looks like you need shell access? Which I don’t have. Is there another way I could install it? Or another Template Engine I could use?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Template Engine

Post by Roja »

anthony88guy wrote:I've never used a Template Engine for my projects but I've worked with some. I'm interested in working with Smarty, but is it possible with a shared host?
Absolutely.
anthony88guy wrote:If you view the Smarty quick install guide it looks like you need shell access?
No, they just use that as the example because its easier to show what to do. You can also ftp the files into a shared host, and access them that way. There is no need for shell access.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I've recently used Smarty for the first time, I love it :) Very easy to use.

Not tried templatelite yet though.

Have previously used just plain old PHP for templating, but sometimes find myself getting in a blur between the presentation and business logic, with the difference in syntax (and [deliberate] limitations) with the Smarty syntax, that is no longer a problem for me. :)
User avatar
mikealeonetti
Forum Newbie
Posts: 5
Joined: Wed Sep 06, 2006 2:52 pm
Location: Long Island

Post by mikealeonetti »

Well the "business logic" and the presentation need not be so far apart. In a perfect world all people who have the ability to design well could work around PHP no problem, but that is in the perfect world. But, if we take logic out of the template code then everything becomes more difficult. I've tried writing a template engine myself that tries to incorporate the easier ends of both. Making things readable and easier on both the designer and the programmer without sacrificing speed (not too much) and readability. Although there was a heck of a lot of support for smarty, it just didn't do it for me.

There are too many template systems out there, and the newer ones just get blown away by smarty. Wish we could get them all together at one domain and give them all a sub-domain so they'd be easier to choose for people.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

mikealeonetti wrote:Well the "business logic" and the presentation need not be so far apart.
I think you mean 'presentation logic' and the template need not be so far apart. The 'business logic' should be kept well apart in my view.
mikealeonetti wrote:There are too many template systems out there, and the newer ones just get blown away by smarty. Wish we could get them all together at one domain and give them all a sub-domain so they'd be easier to choose for people.
I agree.
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

There are also two sides to this discussion, yes templates can be helpful to use for a multidude of reasons, but at the same time they are not neccesarily required or desired. I personally have made the shift to template engines, and back to using standard php. Personally, I don't like having to learn new markup and having the overhead of the template itself, but at the same time a proper caching implementation can reduce overhead greatly.

This is a holy war I'm treading on here, but I thought it important to make a quick remark that there are those of us who do not use them.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Personally, I don't like having to learn new markup and having the overhead of the template itself, but at the same time a proper caching implementation can reduce overhead greatly.
Performance isn't an issue with smarty its got very good caching. But I agree totally with you on the learning issue and so I've never learnt smarty or anything like it. I probably should give it a go one day.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

The concept of a template engine makes sense, but like already said many times before...Smarty is over kill...with a little bit of discipline you can utilize PHP's inbuilt templating functionality, write your own custom caching for much better performance and still get that seperation everyone talks about without having to learn another syntax (Smarty, etc).

As for a single unified list of every template engine: http://www.sitepoint.com/forums/showthr ... did=123769

Poke around the wiki as well: http://en.wikipedia.org/wiki/Template_engine

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

Post by alex.barylski »

ole wrote:
Personally, I don't like having to learn new markup and having the overhead of the template itself, but at the same time a proper caching implementation can reduce overhead greatly.
Performance isn't an issue with smarty its got very good caching. But I agree totally with you on the learning issue and so I've never learnt smarty or anything like it. I probably should give it a go one day.
It's not just that I refer to when I speak of performance...

It's like using any library thats big it adds bloat...Zend Framework is big and even though not all files are used at any given moment, it still adds unessential parsing, etc to your scripts execution...so it does, decrease performance...

You have to balance the time is development with the cost of new hardware...which for me, it's easier to just keep using PHP as it's own template system, it's fast, and only requires moderate discipline (I should take as most projects begin slipping logic into presentation :P ) but still...it could be easily done with some effort

Cheers :)
User avatar
mikealeonetti
Forum Newbie
Posts: 5
Joined: Wed Sep 06, 2006 2:52 pm
Location: Long Island

Post by mikealeonetti »

Well, I believe that when a template is done correctly and it "compiles" he template files into PHP a lot of nasty overhead can be avoided. In this way the only real overhead in the code might result from string indexed arrays. And it is possible to make template syntax as easy as pie by making commands as you expect them to be and letting the code flow be more natural. In reality, more commands, more functionality, more of something doesn't necessarily make things better.

Plus I had a problem a while back because Smarty wouldn't let me embed array loops and I had to write something myself anyway.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Smarty doesn't support array loops???

You weren't using AdoDB were you? :P

Smarty just plain old sucks...

Yes it has caching, but not intelligent caching...it's generic caching for the most part, extendible sure, but so is PHP as a native template langauge...

Smarty might compile but they also fail to inform people that the web pages which need caching the most, like search results on a classified site or a threaded message forum, etc...can't really be cached without programming some custom event caching system, which is difficult to do regardless whether you use Smarty or not... :P

Static boring pages like 'about us' that no one every reads is easy to cache, and is why Smarty is advertised as this advanced compiler type template system...when in reality it's a glorified excuse for OOP in PHP :P

Thats my story :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

OK I'm going to have a bit of a rant here. I accept that quite a few people won't agree with this but I think it needs to be said.
and having the overhead of the template itself
It's like using any library thats big it adds bloat...Zend Framework is big and even though not all files are used at any given moment, it still adds unessential parsing, etc to your scripts execution...so it does, decrease performance...
People place far too much importance on performance. PHP is a high level language that we use because it makes our jobs easier. Libraries are just an extension of this. You deal with performance only when performance becomes an issue by using profiling, at which point you will likely find well written libraries are not the culprit.

If you really cared about performance you would be writing your web applications in C++. The idea is you use each language to the best of its abilities. What is clearly wrong is that people use the performance arguement as an execuse not to learn new stuff or improvement their programming style.

I remember thinking that there was a 50 50 split in PHP with procedural and OO programmers. Procedural programmers claiming to not need OO features and valuing performance more than OO ones. When I went to the first PHPLondon, which is full of high end developers, everyone used OO code heavily and shunned procedural as being a pretty redundant methodology on any PHP 5 enabled server. Some of them talked about some really high level abstractions, which caused a lot of interest here when I reiterated them to you. Why? Because:
  • It make their jobs easier
  • Programmer time is often more expensive than RAM/CPU upgrades
  • The most effective performance increases come through profiling for bottle necks and are pretty specific to each deployment
  • A lot of performance bottle necks will be at data level
  • Peformance isn't always major issue
As programmers we should take the easiest, most flexible/adapatable path in an effort to write maintainable code that has fewest bugs. If performance is important you profile and make modifications where it is necessary.

So returning to the Smarty argument. If you think you have use for it and you like it, use it! If you don't think it will make your life easier don't!
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

People place far too much importance on performance. PHP is a high level language that we use because it makes our jobs easier. Libraries are just an extension of this. You deal with performance only when performance becomes an issue by using profiling, at which point you will likely find well written libraries are not the culprit.
Performance will be an important issue until computers are completely automated...yes it's less and less so every year, but why add bloat when you don't need too???

Thats just naive and bad programming practice IMHO. Why not just have random LOOPs inside your code:

Code: Select all

for($i=0; $i<10000; $i++);
Useless, but eats processor cycles...just like adding the blat of a massive library like Smarty does to your projects...but it eats away at RAM too... :P

Nothing is wrong with templating, I use a PHP variation all the time and have done so for long time. Smarty doesn't offer enough features (which can't be easily emulated using straight PHP) to justify it's cost...

I would argue however that Zend Framework does offer enough benefits to justify it's cost in performance hit.

Smarty basically just assists the presentation layer in helping keep business logic out of it's scope...you can still shoot yourself in the foot however using {php} tags...so really, your just as likely to do so, then if you were going to intermingle logic using straight PHP template engine.

Also, Smarty, from what I remember...IMHO anyways, supports bad design practices...

Keeping the formatting of date/time in the presentation layer is bad...it's likely going to be hardcoded in some format which your used too. Month.day.year - year.month,day, etc...

You could possibly store that value in a smarty config file, but IMHO it's easier to let the business logic determine the formatting of such values, so changes made in the admin section will propagate througout the website immediately. This way you can store your formatting details in DB, config files, XML, etc...
If you really cared about performance you would be writing your web applications in C++. The idea is you use each language to the best of its abilities. What is clearly wrong is that people use the performance arguement as an execuse not to learn new stuff or improvement their programming style
Smarty simply doesn't offer enough advantage to justify it's use...read my previous arguments :P
As programmers we should take the easiest, most flexible/adapatable path in an effort to write maintainable code that has fewest bugs. If performance is important you profile and make modifications where it is necessary.
I'm like water my friend...I follow the path of least resistence all the time...I'm just lazy that way :P

Your arguments are valid, but out of context amigo. Yes, we should adapt to new methodologies and make better use of our time, agreed. But we also shouldn't use something based on the fact some one told us that it's the cats meow, until you fully understand what it is it's offering. Thats called naievty I think.

If someone told you to jump off a bridge, would you follow or think it through first?

Personally I'd always go with the latter ;)

Smarty, although in theory sounds awesome, in pragmatic terms it's nothing more than a glorified version of native PHP template engine, doing nothing but eating clock cycles and chewing RAM by the mega byte.

Template lite is an optimized version of of Smarty which solves some issues of performance, but still doesn't justify using it for anything other than experimentation and research.

If they excluded the {php} at least you would have the argument that it *prevents* not just assists in helping the presetnation logic from mixing with business logic. But they can't do that because logic is occasionally required in both business/presetnation. So why learn a new syntax, which IMHO is kludgey to begin with, when I can just use what I already know, PHP??? :)

Cheers :)
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Hockey wrote:Your arguments are valid, but out of context amigo.


Oles arguments are perfectly on topic, contrary to what you are offering, hockey. You are mostly directly engaging with Ole as a person, not with the arguments he put forward.
Hockey wrote:Yes, we should adapt to new methodologies and make better use of our time, agreed. But we also shouldn't use something based on the fact some one told us that it's the cats meow, until you fully understand what it is it's offering. Thats called naievty I think.
There are estimates that 80% of development time is nowadays used for maintenance, 20% for creating code from scratch. Point is: if the code had been written for humans first and computers second, there would be more time to innovate.
Hardware is dirt-cheap, will get even faster, smaller and with more capacity and bandwidth. Good developers won't get faster, won't get cheaper (on the contrary), won't get smaller and their capacity will cap at some point.

On a meta-level: tone down statements that can be interpreted personal attacks, hockey.
Post Reply