Book Image

Web Development with Jade

By : Sean Lang
Book Image

Web Development with Jade

By: Sean Lang

Overview of this book

Table of Contents (16 chapters)

Sending the variables to the compiler


Defining all of your variables inside your templates would be pretty limiting, so there are a few ways in which we can send data from external sources to templates.

Compiler arg

The easiest way to send data to the Jade compiler is by just providing it in a JSON object that gets passed to the compiler as an argument, as shown in the following steps:

  1. In file.jade, enter the following:

     p= my_content
  2. Run the following command in the terminal:

     jade file.jade --obj '{"my_content":"this text is coming through the terminal"}'
  3. We can see the result in file.html:

     <p>this text is coming through the terminal</p>

Programmatically

Sending variables to Jade programmatically is a bit harder, but offers more flexibility, such as being able to render within the browser. So, using the same initial file (file.jade) perform the following steps:

  1. Run the following command in the terminal:

     jade file.jade --no-debug --client
  2. And we can see the following result in file.js...