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.

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.

August 21st, 2008 at 9:18pm

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.

August 21st, 2008 at 10:11pm

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

August 22nd, 2008 at 1:17pm

Recent Links Tagged With "markup" - JabberTags

[...] public links >> markup Dumb Idea: Let’s write a new templating language Saved by lordtirion on Thu 23-10-2008 Debate – Minimum Markup Law Saved by simusicvideos on Mon [...]

October 24th, 2008 at 1:20pm

bradt.ca » Migrating from Typo3 to Wordpress

[...] dedicated server with only a handful of concurrent users and caching turned on.  A few months ago, I picked on Textpattern and how it invented another templating language.  That was such a minor offense compared to the [...]

November 5th, 2008 at 10:00am

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

July 1st, 2009 at 7:13am

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>