我正在使用grunt-html-build使用模板制作静态网站的插件。
我想知道是否可以将自定义 parameter 对象传递给 grunt-html-build
的 build 函数,如下所示:
<!-- build:section layout.head(customSettings) -->
<!-- /build -->
在模板文件中包含,如下所示:
<title>customSettings.title</title>
<meta property="og:title" content="customSettings.fbTitle" />
最佳答案
使用grunt-bake相反,它有一个内联部分语句 它允许传递自定义参数对象,示例配置是
要通过 grunt-bake
包含其他内容的 HTML 文件
<html>
<body>
<!--(bake includes/file.html _section="home")-->
</body>
</html>
file.html
文件
<h1>{{title}}</h1>
<p>{{content}}</p>
包含 _section
属性中提到的 home
对象信息的 JSON 文件
{
"home": {
"title": "Home",
"content": "This is home"
}
}
最后是grunt-bake
任务的配置
grunt.initConfig({
bake: {
build: {
options: {
content: "content.json"
},
files: {
"baked.html": "filetobake.html"
}
}
}
})
关于javascript - 咕噜JS : passing parameter to grunt-html-build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31029102/