Monday, July 16, 2012
The Power of a New Templating System
The task of maintaining a medium-to-large size website is daunting, and trying to do it manually can lead to all kinds of problems, including broken links, missing assets, and inconsistent appearance.
Content management systems address this problem by providing a templating system, which specifies how dynamically generated content will be laid out among otherwise static assets.
The simplest templating systems work very much like mail-merge word processor documents, inserting fields from a database into select locations. More sophsiticated systems allow for styling adjustments or even drag-and-drop layout management.
Over the past five months, our team has been developing and refining a brand new templating system, which is replacing the system we've had in place for the previous four years. We're using it to render our own Content Hub, and new clients will be using it as a starting point.
The new system is built upon a newer PHP-based templating system called Twig, which is a product of Sensio Labs. We chose it to replace our existing XML rendering system for several reasons:
Less Stringent Syntax -- Under the old templating system, syntax mattered everywhere because XML processors require that the document be "well formed" with respect to XML's syntax rulres. With the new templating system, syntax matters only in the areas where Twig is actually executing code. In principle, one could use the saved HTML from a company's website as a starting point for a new template on the new system. On the old templating system, lots of manual adjustments were required.
Still Secure Against Arbitrary Code Execution -- When we designed the XML templating system back in 2008, one of our requirements was that it had to be safe against the execution of arbitrary code, which is the bane of existence for many free blogging applications. Not protecting against this vulnerability would make our platform less secure. With ill-tested code, one bad template could quite possibly take down an application server. Unlike other PHP systems, Twig provides robust sandboxing, which prevents the insertion of harmful code.
Better Flow Control Handling -- More sophisticatted designs require lots of conditionals and loops. Conditionals ensure that certain things are displayed only on the right circumstances. Loops provide a succint means of communicating repeated operations, like the display of posts. With the old XML system, loops and conditionals had a very awkward syntax, which borrowed heavily from XSL, an XML language for transforming XML into something else. Twig's elegant syntax makes expressing these operations a breeze.
Nesting of Templates -- With the old XML-based system, all possible markup that could appear on a page had to be expressed in one XML document. Twig allows for embedding template assets within other templates, making it possible to split out the header, footer, and other sections of a page into separate files.
But Wait! There's More!
Our user interface for managing Twig templates is a huge value-add, which includes the following benefits:
Easier Asset Management -- Asset files, like style and images, can be uploaded and managed easily through the user interface. Under the old system, these assets had to be hosted elsewhere or uploaded through other parts of the application.
Easy-on-the-Eyes Code Editing -- Editing XML source in the old templating system was a task for only the bravest of the brave. Aside from the default indentation at the start, there was little to go on. The new system uses the Ajax.org Cloud9 Editor, which provides syntax coloring, a nice way to communicate the role of the code on the page.
More Widgets with More Configuration Options -- A template widget is essentially collection of markup, styling, and behavior, which specfies a frequently used page component, like a post listing or a call-to-action image. The new system introduces new widgets, like the post archive link listing, and many of the widgets are configurable by the network administrator outside the context of the template editor, making it easier for non-designers to make small updates to the site.
All of these things make it easier to create a content marketing hub that matches your brand in a shorter amount of time. Moreover, it's much easier to maintain.
Does your content marketing software provide you with this much control at this level of simplicity? If not, then consider getting in touch with our sales team to learn more about this and many other benefits of using Compendium!