从命令行将变量传递给 jade 模板 [英] Pass variables to jade template from commandline

查看:48
本文介绍了从命令行将变量传递给 jade 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用 jade 模板来生成不同的 html,具体取决于它是在开发中还是在生产中.目前,我不打算在 node.js 中编写代码.鉴于此,是否可以从命令行调用 jade 并传递变量?如果是这样,如何?

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?

如果,index.jade 是

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.

谢谢

推荐答案

您需要在 Jade CLI 中使用选项 -O/--obj.它接受两种类型的值:

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

  • 序列化 JSON
  • JSON 文件的路径(优先)

例如:

jade -O myfile.json template.jade

jade --obj '{ "cache": true }' template.jade

这篇关于从命令行将变量传递给 jade 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆