Charlton Roberts

Creative Developer, Squarespace

“Machinery has been taught arithmetic instead of poetry.”
Charles Babbage, 1832

How to dynamically load the date in Jade using Javascript's Date()

Problem

I need to add the current year in a footer for the copyright, just like you can do with PHP. But, I'm using Node + Express + Jade templating.

Jade loves Javascript

Sometimes I forget, but Jade evaluates raw Javascript. Frequently I use it to evaluate the locals variable for dynamic content. But when compiling the Jade, you have access to the entire Native SDK.

The Solution

Mine just wanted the date, but presumably you could do a great deal of rendering logic right in the Jade file. Similar to what the Helpers do something in a Ruby on Rails project. Anythings extremely page-specific and last minute.

footer © #{new Date().getFullYear()} Charlton Roberts. All Rights Reserved.

Next,

I wonder what context the process that actually rendering the Jade lives in. Is anything else in scope..?