Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variables to jade template from commandline

Tags:

pug

I'm planning to use jade templates to generate different htmls depending on if it is in development or in production. At this time, I'm not planning to write code in node. Given this, is it possible to invoke jade from commandline and pass variables? If so, how?

if, index.jade is

!!! 5
html
  head
    title my jade template
  body
    h1 Hello #{name}

I want to invoke it from command line passing value for name.

Thank you

like image 344
jjude Avatar asked Jun 12 '13 02:06

jjude


1 Answers

You need to use the option -O/--obj within the Jade CLI. It accepts 2 type of values:

  • Serialized JSON
  • A path to a JSON file (this takes precedence)

For example:

jade -O myfile.json template.jade

or

jade --obj '{ "cache": true }' template.jade
like image 152
gustavohenke Avatar answered Oct 23 '22 10:10

gustavohenke