Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Web Development with Jade

You're reading from   Web Development with Jade Knowing Jade makes life simpler and more productive for web developers, and this book will teach you the language concisely and thoroughly using lots of practical examples and best practices for a solid grounding.

Arrow left icon
Product type Paperback
Published in Mar 2014
Publisher
ISBN-13 9781783286355
Length 80 pages
Edition Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Sean Lang Sean Lang
Author Profile Icon Sean Lang
Sean Lang
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime