javascript - 如何将脚本 src 传递给 jade 模板

标签 javascript node.js express pug

我有一个 jade 模板,我想将它作为脚本 src 传入一个变量,因为在不同的路由上脚本会发生变化。我如何在 Jade 和 Express 中执行此操作?

doctype html
html
  body
    #app!= html

  script(src={bundle})

在脚本 src 中传入我想要的 bundle 变量

var html = React.renderToString(node)
var bundle = '/public/js/bundle.js'

res.render('layout', { html: html, bundle: bundle })

最佳答案

看起来我可以自己回答这个问题,在这个 question 的帮助下

如其所述,# 用于转义数据,! 用于原始数据。

doctype html
html
  body
    #app!= html

  script(src='#{bundle}')

关于javascript - 如何将脚本 src 传递给 jade 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30585931/

相关文章:

javascript - Rails 将请求解析为 html,即使它是 json

node.js - visual studio 代码 node.js 调试器无法在标准启动时附加

javascript - 如何增加 Vue 应用程序的 max-http-header-size

javascript - 检查所有参数的助手node.js - sails - Express

javascript - 如何在 promise 中返回请求

javascript - JSON 数据应该覆盖 JSON 模式吗? (通过 jdorn/json-editor 使用架构和数据)

javascript - 如何使用nodejs和expressjs在mysql上显示数据

node.js - 无法更新 Mongoose 中的createdAt属性?

javascript - THREE.js 代码仅在存在断点时运行

node.js - echo 忽略 child_process.exec() 中的标志