Pass variables to jade template from commandline

你说的曾经没有我的故事 提交于 2019-12-21 04:11:13

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/17056617/pass-variables-to-jade-template-from-commandline

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!