Wednesday, 12 June 2013

JQTPL old "tmpl" method is now "render"

To anybody who uses JQTPL already this will be obvious, but I just thought I'd post this for anybody who might have gone down the path I did.

As I mentioned in this post on Stack Overflow I'd been trying to get node.js set up (on my Mac) per Adam Freeman's Apress Book "Pro JavaScript for Web Apps".  The issue I was facing is that it seemed the API changed for JQTPL such that there is no longer a "tmpl" method as implied by this, and also as is clear from reading the source code of jqtpl.js (the current version of which only appears to have "render", "compile", "cache" and "$" methods as per this page.

Adam's code from his "server.js" file contains the following line:

    res.write(jqtpl.tmpl(loadTemplate(req.url.substring(1)), data));

which causes the following error:

    TypeError: Object # has no method 'tmpl'
        at IncomingMessage. (/Users/dave/NodeJsTesting/server.js:43:45)
        at IncomingMessage.EventEmitter.emit (events.js:92:17)
        at _stream_readable.js:910:16
        at process._tickCallback (node.js:415:13)

It turns out (if you're using a more recent version of JQTPL like I was) you just have to change "tmpl" to "render" in Adam's "server.js" file.


Thanks to Hitachi Consulting UK.

After two years at Hitachi Consulting UK I decided it was time for me to become an independent contractor.

I really appreciated the opportunity to work at Hitachi.  I got the chance to work with some really nice and some incredibly smart people, from whom I learned a great deal, particularly about Test-Driven Development, Agile methodologies, and in general, best practices in software design and development.

I've read quite a number of vital technical books recommended to me by people I worked with there, and my reading list continues to expand.  I also got some excellent commercial experience in a number of industries, worked with WPF, Silverlight, and MVC, and picked up a couple more Microsoft certifications during that period.

Finally I've got a clearer vision of what it takes to achieve real mastery as a software developer.  It's about continuous improvement and lifelong learning, and I can't claim to have mastered everything yet (since there's so much to master).  But a couple years of Hitachi has definitely got me a lot closer.

So I just wanted to say thanks to the fine people of Hitachi.  I'm a better developer for having been there.