The best web templating language I’ve used to date is the Template Attribute Language: TAL. It was originally developed for Zope, a fantastic python web application platform.
Most templating languages use special characters like [% foo %] or <%= foo %> to put dynamic content into a web page. TAL uses HTML attributes to put dynamic content in a page:


The benefit of doing it this way is that WYSIWYG editors can render page templates. Designers can edit your page templates easily, and you don’t have to worry about outside tools messing up your templates. You can also use HTML elements as your structure.

<h1 tal:content="here/title">Lorem Ipsum</h1>
<table>
<tr tal:repeat="row here/data">
<td tal:content="row/col1">dummy data</td>
<td tal:content="row/col2">dummy data</td>
</tr>
</table>

The <h1> tag will replace “Lorem Ipsum” with the title variable, and the table will loop over the data variable and write a <tr> for each element. This is so much better than other templating languages because it uses the page structure to fill in you HTML.
So that’s great if you use Zope or Plone, an awesome content management system. But what if you don’t? Other developers have seen how cool TAL is and ported it all around. There’s a Perl module Petal (via 0xDECAFBAD) and a PHP package PHPTAL. If you’re doing any sort of web application development, you owe it to yourself to check out TAL.

,

5 responses to “XHTML templating joy”

  1. l.m.orchard says:

    And there’s also a standalone implementation in Python, in case you don’t feel like using all of Zope:
    http://www.owlfish.com/software/simpleTAL/

  2. Gadgetopia says:

    TAL: Template Attribute Language

    XHTML templating joy: I looked into TAL a bit when I was on my Zope fling last year. It is handy to be able to have all sorts of dummy content in your template while you’re developing it. The benefit…

  3. Cool. I’ll have to check it out. I’ve tried out quite a few templating systems and CMS) to build my site (Plone, Drupal, Typo3, etc.) and none have panned out so far, so I rolled my own lightweight system. It would be nice to have something better though at least for templating.

  4. Leslie, I meant to point to SimpleTAL, thanks.
    Jessica, I think you’ll be pretty happy with TAL, it is the most logical HTML templating system. And if you’re a standards nazi, it’ll validate as XHTML compliant too.

  5. MickBlog says:

    More TAL implementations

    90% Crud: XHTML templating joy lists a couple more TAL implementations, Petal, a perl one, and a PHPTal, a PHP…

Leave a Reply