Jade: a clean, whitespace-sensitive template language for writing HTML
February 20, 2015
Jade is a high performance template engine heavily influenced by Haml. It is designed for writing HTML pages using a concise, modern syntax without the verbosity of old fashioned XML-like tags that we all want to forget about. The new rjade package implements convenient bindings from R to this popular JavaScript library.
An example template
Below an example of a Jade template, taken from the jade homepage. Notice that the notation of tags, classes and id’s much resembles CSS selectors. The template also includes one variable called youAreUsingJade, which we can use to control the rendering output.
Converting a template to HTML text involves two steps. The first step compiles the template with some formatting options into a closure. The binding for this is implemented in jade_compile.
The second step calls the closure with optionally some local variables to render the output to HTML.
The output looks like this:
Note how the HTML output changes when setting local variables:
That’s it. Hover over to the jade website to learn about the full power of this amazing templating language.