Docpad and Jade

jade buddha

As you may realise, this site is entirely written in Node.js using the Docpad framework. I've also started using the Jade templating plugin. Docpad is able to run a number of templating systems such as Eco or Markdown - as well as straight html. And they can all be running simultaneously within the one application (although I would imagine it might be quite tricky for a developer to be constantly switching templating systems).

A lot of node applications, however, seem to use the Jade templating system. I'd mostly been using CoffeeScript and Eco up until now. So I thought it was time to get into Jade. It was a bit of a learning curve. Below is the Jade code that generates the home page. You'll notice that it actually calls a Docpad "partial" written in CoffeeScript, which was actually legacy code written for a previous version of the site. The plan was to update that code to Jade - but it does demonstrate the interoperability of Docpad.

				h4 Node.js and Web Development
				h1 Steve McArthur
		.row.centered-text(style='margin-top: 4em; margin-bottom: 3em;')
					| Hi, Im Steve, a Web Developer specializing in Javascript and Node.js development.
				| Originally from Perth, Western Australia, now living in the UK.
			- posts = getCollection('posts').toJSON()
			!= partial('',{posts:posts,number_posts:3,trimTo:500})
Share this Post:
comments powered by Disqus