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
# Compile a Jade template in R library(rjade) text <- readLines(system.file("examples/test.jade", package = "rjade")) tpl <- jade_compile(text, pretty = TRUE)
The second step calls the closure with optionally some local variables to render the output to HTML.
# Render the template tpl()
The output looks like this:
%MINIFYHTMLff823b06a91aba8342ac7806a64a34e39% Jade - node template engineid="container" class="col"> Get on it! Jade is a terse and simple templating language with a strong focus on performance and powerful features.%MINIFYHTMLff823b06a91aba8342ac7806a64a34e310%
Note how the HTML output changes when setting local variables:
tpl(youAreUsingJade = TRUE)
%MINIFYHTMLff823b06a91aba8342ac7806a64a34e311% Jade - node template engineid="container" class="col"> You are amazing Jade is a terse and simple templating language with a strong focus on performance and powerful features.
That’s it. Hover over to the jade website to learn about the full power of this amazing templating language.