 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
WorkingSoftware Blog: Your templating engine sucks & everything you've written is spaghetti code
by Chris Cornutt December 14, 2011 @ 12:03:54
In a bit of a ranting post on the WorkingSoftware.com.au blog Iain Dooley shares his opinion about most of the code he's seen, specifically related to templating engines: "Your templating engine sucks and everything you have ever written is spaghetti code (yes, you)".
Templating is a real hot button in the web development community. [...] The high horses that people usually get on are that all too familiar TLA MVC (Model/View/Controller) architecture and "separation of presentation and business logic". The poor pedestrians upon which they look down are those who have written "spaghetti code" - templates where presentation logic, markup, business logic, database access configuration and whatever else you might imagine are mixed up in the same file. Well, I've got some news for you: you're all wrong.
He points out that, with most of the major templating tools out there, there's most people still put some sort of business logic in their templates. Rarely will you find a "pure" template that only echoes out the data. He gives an example of a Mustache template with "empty" logic in it. He shares a new term his coined too: "Template Animation". This is the separation of the templating process as it is usually done and splitting it so that the output is a modified DOM resource rather than a static template.
He talks about some of the advantages of this approach and an example of its use in an example of a logged in user vs not logged in user as well as a brief discussion of Markdown/HAML.
The only thing that Template Animation advocates is that the technological barrier between the frontend and the backend is never crossed - that our templates are truly logic-less.
There's lots of comments on the post already - everything from support of the idea to systems that already implement this sort of idea to disagreeing opinions.
voice your opinion now!
opinion templating engine logic separation templateanimation
Smashing Magazine: Getting Started With PHP Templating
by Chris Cornutt October 18, 2011 @ 09:15:49
On the Smashing Magazine site today there's a new post introducing you to templating in PHP applications. They cover both the creation of a simple, custom templating library as well as using a more widely known too - Twig.
In this article, we'll cover how to separate the view of your PHP application from its other components. We'll look at why using such an architecture is useful and what tools we can use to accomplish this. [...] To fully benefit from this article, you should already know how to write and run your own PHP scripts on a Web server (i.e. using Apache).
They start with the very basics of templating, mostly pointing out how it reduces the dependency of having layout code directly in your application's logic. It makes things easier to reuse and makes for better code structure in the long run. They mention other templating engines like Smarty, PHPTAL and Twig, but focus in on the last for their code samples. They show basic templating, making reusable templates, applying filters and working with simple control structures.
voice your opinion now!
templating tutorial introduction twig smarty phptal
Ryan Mauger's Blog: Using Twig with Zend Framework
by Chris Cornutt May 05, 2011 @ 08:28:18
Ryan Mauger has written up a new post about an integration he's done using the Twig templating engine (from be Symfony community) with his Zend Framework application to make view handling simpler.
Mostly I thought [what Twig offered] were silly things that were not really needed unless you had a team of designers to work with, however, during my exploration, a couple of things occurred to me that I had not considered about templating systems before. One being the enforced separation of concerns they provide; you simply cannot do anything from inside them which you shouldn't be, keeping your presentation very very clean. The second, being that they're not all as terrible as Smarty.
He helps you get Twig installed (via PEAR chnnel) and includes the code for an application resource and the changes you'll need to make to your application.ini to get things working. He uses a base controller setup, so he shows how to introduce a "twig()" method into that to help with rendering. Finally, there's a sample class included that includes two actions, both using this "twig()" method to pas the output data through the twig interpreter and out to the view.
voice your opinion now!
twig templating tutorial zendframework example pear
Zend Developer Zone: Creating Web Page Templates with PHP and Twig (part 1)
by Chris Cornutt April 07, 2011 @ 12:44:43
On the Zend Developer Zone today there's a new tutorial from Vikram Vaswani about using the Twig templating engine in your application. It's part one of a series that introduces the library to you and includes examples of some of the most common templating logic.
Most PHP frameworks, including Zend Framework, Agavi, CakePHP and CodeIgniter, come with built-in templating to enable this separation. However, if you're not a big fan of frameworks, or if your project is small enough that you don't need the additional overhead, you can also consider using a standalone template engine to obtain the same benefits. A number of such engines exist - you've probably already heard of Smarty, Savant, Dwoo and others - and in this article, I'll introduce you to one I discovered rather recently, called Twig.
The Twig project gives you a framework-independent tool for creating simple (or complex, if you'd like) templates for the output of your site. He shows you how to get it installed (via PEAR) and provides some sample templates for things like:
- using conditionals (if/else/etc)
- looping
- working with arrays from PHP
- including other templates
- using included filtering on data
voice your opinion now!
tutorial twig templating introduction
Rob Peck's Blog: PHP Templating Celebrity Deathmatch!
by Chris Cornutt August 14, 2007 @ 15:37:50
The Code Lemur blog (as penned by Rob Peck) has a new post - a "deathmatch" for two of the PHP-associated templating solutions out there in a fight to the finish - Smarty and Blitz.
In this test, I am going to be comparing Smarty (the most widely used PHP templating engine and an official PHP project), Blitz (a new templating engine currently under very active development that is native compiled as a PHP extension), and standard PHP includes.
He compares them on three different levels - instantiation, simple template rendering, and complex testing. Each time, there's a victor but in the end, there's really only one "winner" - the PHP language itself that does a great job of templating things easily without the overhead of adding in external libraries.
voice your opinion now!
templating deathmatch blitz smarty compare templating deathmatch blitz smarty compare
Felix Geisendorfer's Blog: Basic CakePHP templating skills
by Chris Cornutt October 12, 2006 @ 07:44:00
From the ThinkingPHP blog today, Felix Geisendorfer has shared some of his experience to help those CakePHP users out there that are looking at doing more templating to their applications than just the normal index changes.
One of the things I don't see getting to much coverage is how to create good templates when working with CakePHP. Since those are written in plain PHP, this does not apply to CakePHP only. So I'm sure many people have already developed their own style that they are comfortable with and I don't ask for them to change it. However, maybe some people new to the framework / language can benifit by taking a look at the one I'm using.
He covers a few different topics:
PHP tags
- Conditions
- Loops
- the linebreak issue
- avoiding multi-line statements
- Creating Zebra striped table rows
The code included on some of the points (not the multi-line or the PHP tags items) is simple and is summed up in less than six lines.
voice your opinion now!
cakephp templating skills basic framework condition loop linebreak zebra cakephp templating skills basic framework condition loop linebreak zebra
Pádraic Brady's Blog: Template Lite A Sweeter Smarty Alternative
by Chris Cornutt September 20, 2006 @ 15:53:02
In his latest blog post, Pádraic Brady talks about a "sweeter alternative" to using Smarty for your site's templating - Template Lite.
Use the term Template Engine in a PHP forum and the word "Smarty" will inevitably crop up. I like Smarty but, similar to a few PHP libraries, it's very bloated.
I try to keep my applications lean and mean - small, fast, and adaptable. Unfortunately, Smarty disagrees with my needs. It's bloated design while packing a mighty punch, uses a chunk of memory and processor time I dislike. Since I also develop open source apps which end up on shared hosts, my concerns are even more justified.
Enter Mark Dickenson. Mark is the developer of a Smarty alternative: Template Lite.
He talks about what Template Lite is and what kinds of advantages it has over Smarty, including staying try to its name. Pádraic measures it as not only being faster but also having 50% of the memoery footprint that Smarty does. He seems to favor it for those places when he just needs something light and easy on a site.
voice your opinion now!
smarty sweeter template lite templating faster lighter smarty sweeter template lite templating faster lighter
Khalid Hanif's Blog: Problems with Simple Testing
by Chris Cornutt April 29, 2006 @ 07:48:16
The "Jelly & Custard" blog has a good reminder today for both those experienced with templating in PHP and those just starting out - be careful how you include.
Its quite common for people to have one main template, and 'include' their content into the main content area. This works well for small informational sites, where the main content is the bit that changes on each page.
There's nothing wrong with this as such, however, the issue is when the input isn't validated.
He gives one or two examples of how it's usually implemented, how it can be exploited, and two ways to help combat the problem - a php.ini setting and some simple input validation.
voice your opinion now!
simple templating problem input validation simple templating problem input validation
|
Community Events
Don't see your event here? Let us know!
|