Blog

Dumb Idea: Let’s write a new templating language

August 21st, 2008 at 10:30am | 6 Comments

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.

WP Migrate DB Pro - Get 20% Off!

Way back in 2009, I released a free plugin called WP Migrate DB which became pretty popular in recent years. So, I decided to develop a Pro version of this plugin which eliminates the manual work of migrating a WP database. It allows you to copy your db from one WP install to another with a single-click in your dashboard. Especially handy for syncing a local development database with a live site. Learn more »
Get 20% off — Coupon code: BRADTCA20.

About the Author

Brad is founder of Delicious Brains, a company building super awesome products for WordPress, including WP Migrate DB Pro, a huge time saving tool for WordPress developers.

  • http://textpattern.com/contributors#developers Robert ‘wet’ Wetzlmayr

    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.

  • http://bradt.ca/ Brad Touesnard

    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.

  • http://jsrepeater.devprog.com Shawn_S

    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:
    http://jsrepeater.devprog.com/

    There is an example of its use transforming the data from the Google Search API at:
    http://jsrepeater.devprog.com/google.search.websearch.example.html

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

  • Pingback: bradt.ca » 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