Dumb Idea: Let’s write a new templating language

At work, we’re going to be redesigning a site that is running Textpattern.  As I’ve never worked with Textpattern before, I’ve been brushing up.  After about two minutes of reading, I find out that it has it’s own XHTML-style templating language.  Textpattern immediately loses a lot of credibility.

The article I was reading rationalizes the creation of Textpattern’s templating language:

Textpattern is aimed squarely at web designers, not PHP geeks or novice bloggers. Its template tags use a syntax that’s identical to XHTML, and thus familiar and convenient for designers.

Templates specify presentation, so they’re written in a style already familiar to a web designer. A PHP-based template syntax might be convenient for software developers, but PHP is a procedural programming language, not a markup language.

Although there are a couple points in these excerpts that are correct (i.e. “templates specify presentation” and “PHP is a procedural programming language, not a markup language”), the logic is just plain wrong.  Sure, the templating language has the same “style” as XHTML, but it’s not XHTML.  So no matter what other languages (templating or programming) the designer is already familiar with, they still have to learn this new one.

I am a fan of PHP-based template languages for three fundamental reasons:

  1. There’s hardly anything to learn if you’re already familiar with PHP (a lot of people are, even “designers”)
  2. If you aren’t already familiar with PHP, you learn a useful language
  3. PHP is very well documented (unlike some of these templating languages)

And why an XHTML-style templating language?  The author of the article contends that designers are already familiar with that style.  But who are these designers anyway?  Designers may have dealt with templating in the past, but nowadays they generally stick to Photoshop and Illustrator.  The frontend developers are usually the ones dealing with templates and they never deal exclusively with markup.  They are also into CSS and usually Javascript as well.  And since the basic control structures (if, else, while, for, etc.) in Javascript and PHP have nearly identical syntaxes, a PHP-based template language would be a lot more natural for frontend developers.

And even if you’re hell bent on creating an XHTML-style templating system, why invent a new language?  Because it’s fun is not a good reason.  There’s lots of popular languages already out there.  Perl’s HTML-Template is a good example.

So, unless you’ve come up with some innovative templating syntax, writing a new templating language is not only reinventing the wheel, it’s just plain dumb.

  • Hint: Think XML, XSLT and the applications thereof (MathML, SVG). See a pattern?

    I wouldn’t name XML dumb without a reasonable cause, and would even expand this stance to XML-inspired domain-specific transformations.

  • I’m not saying XML or markup languages in general are dumb. That would be ridiculous.

    I’m saying inventing yet another templating language is dumb and it’s especially dumb to invent one with an XHTML-style given the skill sets of those who work with templating systems.

    No offense to yourself or the Textpattern team. I’m sure the decision to develop a new templating language was made a long time ago. As was the base64 encoded plugins concept.

  • I think we are all … OMG, I love the auto-preview as you type thing you have going on your blog :- ) ….

    … as I was saying, I think we are all fighting this template thing. For some of us the impetus is that we are now suddenly faced with javaobjects instantiated from JSON received through AJAX calls which somehow have to find themselves in the markup.

    The traditional way if to have a loop in javascript iterating through the data and adding nodes to the DOM.

    This is the sort of stuff that some can do with their eyes closed yet still find irritating.

    The fact of the matter is that it is easier to change HTML than to change javascript that generates HTML. Because of this I have gravitated to a templating concept that uses the HTML as a template and the JavaScript simply to populate the template via innerHTML.

    Perhaps you might be interested in having a look at it:

    There is an example of its use transforming the data from the Google Search API at:

  • Pingback: Recent Links Tagged With "markup" - JabberTags()

  • Pingback: » Migrating from Typo3 to Wordpress()

  • giovanni

    nothing to say. i love Textpattern and Expression Engine, with the latter my favourite. … but mainly wanted to see the “preview” widget in play. nice!

    oh, one thing. if you are a clever TxP expert would love to hear from you. cheers all!

    ps Brad.. may need you for a WP project for our organization

  • Harm Meijer

    Got to this post through your reply on “What is WordPress Lacking? A Template Language”.

    think the biggest advantage is that a good template language forces
    your presentation only to have simple logic like if and loop statement
    and filters that can be defined somewhere else (convert date to
    something like “yesterday”. This can be learned quickly by someone who is great with designing pages but doesn’t know anything about programming.

    will force you to prepare the data first (PHP) and then feed it to your
    template. It enables/forces you to separate your logic and
    presentation. When things change or you work in a team it’ll make your
    life easier eventually. You can do this in PHP as well and don’t need a
    template for it but many people end up writing functions.

  • As PHP CMS’s get more complicated, templating languages become more important.

Comments Elsewhere