Smarty templates for classifieds software
Hello everybody,
Need your opinion on the Smarty template engine. We’ve included it in our classifieds software packages [links removed] as a part of template management system. Do you think if Smarty is an advantage in template management? Are there any pitfalls in using it?
Abhishek Reddy posted this at 12:29 — 13th October 2006.
He has: 3,348 posts
Joined: Jul 2001
I'm afraid I'm not much of a Smarty fan...
Yes, there are pitfalls. Smarty itself falls into a trap of reinventing wheels that, I think, domain-specific languages often do.
The motivation for Smarty is fine: to separate application and presentation. However, I don't see how that implies reimplementing a whole language -- albeit a restricted (but growing!) one.
To cope with presentation logic, Smarty has reimplemented control structures like conditional branching, looping and so on, which belong to a general-purpose language. In this case that language is PHP, already at hand where Smarty is. Therefore Smarty becomes redundant, and adds unnecessary complication.
PHP can be used for both application and presentation logic, even to make templates. Along with otherwise good systems architecture, one merely needs to keep business logic out of the presentation layer, which requires a little discipline.
Ironically, even Smarty has the same challenge:
I think all the benefits of Smarty are consequent to the general good practices that it encourages; and not a result of ingenuity in the Smarty implementation itself. As well as PHP, even XML/XSLT -- if you are so inclined -- can be used in a three-tier MVC-like approach, for instance.
One example of a simpler presentation layer that doesn't reinvent the wheel is phptemplate for Drupal. While I admit that a presentation language embedded -- rather than only implemented -- in PHP would be preferable even to phptemplate, that wouldn't be a realistic expectation given PHP's limitations.
So Smarty is a great idea, but I wouldn't use Smarty to practise it.
JeevesBond posted this at 16:19 — 13th October 2006.
He has: 3,956 posts
Joined: Jun 2002
Have to agree with Abhi here. In plain, non-software engineering terms: it's overcomplicated. By the time you've learnt how to use Smarty you might as well have just written everything in PHP.
What alternatives are there to Smarty Abhi? I know about phptemplate, but that only works for Drupal (?).
a Padded Cell our articles site!
Abhishek Reddy posted this at 05:37 — 14th October 2006.
He has: 3,348 posts
Joined: Jul 2001
I don't think you need an alternative package as such. You can put the template idea to practice with an appropriate system architecture in your application. Which to a large extent amounts to avoiding directly calling business routines or writing data from the template.
A Model-View-Controller approach often works out reasonably well. Have a look at Rasmus Lerdorf's toy no-framework PHP MVC framework, a neat example of keeping it simple. While I don't wholly like Marston's version of PHP MVC that I linked to in the last post (it's kind of large), it also shows the same basic point that Lerdorf's does:
In practice, all this matters only for web applications that aren't maintainable without a separate presentation system. Smaller sites can frequently get away with far less effort expended in architecture.
(... as far as PHP goes, anyway.)
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.