Chameleon, browser-side templates, meta:interpolation

(Leaving a reminder for myself about meta:interpolation=”false” in Chameleon. Thanks Wichert and Malthe for the answer.)

For KARL and other recent projects, I’ve been doing a good bit of jQuery and jQuery UI.  Lately I’ve dabbled in browser-side templating, first with John Resig’s microtemplating, now with the new, officially-supported jQuery Templates.

Both use a pattern of defining templates in the HTML as markup inside a <script type=”something different”> block. The <script> prevents the DOM from displaying it and the value of “something different” prevents JS from interpreting it.  In the template, you insert variable values using special delimiters.  For the latter, it is ${somevar}.

Which conflicts with Chameleon.  There are workarounds.  For example, you can also insert a variable using {{= somevar}}.  Or you can load your templates from a separate file and insert as data into the template during rendering (after parsing).

I didn’t realize, though, that Chameleon already provides for this.  Put meta:interpolation=”false” on a block, and Chameleon won’t go after ${} expressions.

Alas, this doesn’t solve how Resig’s microtemplating works, which uses <% %> as delimiters.  In recent Chameleon versions, expat barfs on percent as a startTag.  Malthe said Chameleon 2.0 (work-in-progress) will allow this.

Advertisements

One Response to “Chameleon, browser-side templates, meta:interpolation”

  1. brad clements Says:

    I keep kicking myself for not finishing up and publicizing jstal or tal2xslt

    well anyway .. needs some tidying up and jslint, but I’m using it every day

    http://bazaar.launchpad.net/~bkc/atali/trunk/annotate/head%3A/jstal/jstal.js

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: