Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As a highly satisfied user of the smarty templating system, I want to refer you to this (from http://www.smarty.net/whyuse.php):

) Designers can't break application code. They can mess with the templates all they want, but the code stays intact. The code will be tighter, more secure and easier to maintain.

) Errors in the templates are confined to the Smartys error handling routines, making them as simple and intuitive as possible for the designer.

) With presentation on its own layer, designers can modify or completely redesign it from scratch, all without intervention from the programmer.

) Programmers aren't messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.

) Templates are a close representation of what the final output will be, which is an intuitive approach. Designers don't care how the content got to the template. If you have extraneous data in the template such as an SQL statement, this opens the risk of breaking application code by accidental deletion or alteration by the designer.

) You are not opening your server to the execution of arbitrary PHP code. Smarty has many security features built in so designers won't breach security, whether intentional or accidental. They can only do what they are confined to in the templates.



When you end up with flow-control, and other such complicated constructs, inside your templates, either the designers are already smart enough to "modify or completely redesign it from scratch, all without intervention from the programmer", or the programmer will need to be "messing with templates" anyway, to help the designers fix their logic errors, which no amount of abstraction will help overcome.

The problems solved by Smarty could be solved simply with a single try-catch block around the rendering-kickoff logic (that forwards to a nice 500 error page if something happens), and a convention to not do any business-layer stuff within the templates. [Also, source control + a dev/testing server to deploy on so "break[ing] application code" isn't a concern, but this should really, really not need to be mentioned.] This is exactly what I've done on any [non-framework] PHP project I've touched, and no one has ever complained that it was hard to edit the views.


All valid points, which I agree may be helpful for some although, again they only serve as abstractions.

) Errors in the templates are confined to the Smartys error handling routines, making them as simple and intuitive as possible for the designer.

- Ok, but this is an abstracted error message, when the designer could simply learn to work with PHP error messages.

) Programmers aren't messing with templates. They can go about maintaining the application code, changing the way content is acquired, making new business rules, etc. without disturbing the presentation layer.

- If you are using an MVC design pattern programmers will rarely need to mess with templates anyway.

) You are not opening your server to the execution of arbitrary PHP code. Smarty has many security features built in so designers won't breach security, whether intentional or accidental. They can only do what they are confined to in the templates.

- I thought it was possible to execute abritrary PHP code by using the {php} template tags?

I suppose at the end of the day you use what feels most natural for you and what your designers find easiest (or are familiar with). It's totally up to personal preference. For me it has always felt like too much of an abstraction to be worth utilising.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: