javascript - 咕噜JS : passing parameter to grunt-html-build

标签 javascript plugins gruntjs grunt-html-build

我正在使用grunt-html-build使用模板制作静态网站的插件。 我想知道是否可以将自定义 parameter 对象传递给 grunt-html-buildbuild 函数,如下所示:

    <!-- 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/

相关文章:

javascript - 如何缩小 AngularAMD 代码?

javascript - 使用 React Router v4 检查特定的 url 结尾

c# - asp.net 中的.net 2.0 winform 控件

eclipse - 以编程方式更改 Eclipse 中的背景颜色

javascript - grunt-bower-task 正在从 Bower_components 中删除 CoffeeScript,然后提示它丢失了

javascript - 如何在 Grunt 中分别连接多组脚本?

javascript - Python 爬虫机械化/javascript

javascript - HTML/JS : datetime display-er

css - 如何仅将 CSS 添加到 WordPress 插件的选项页面?

javascript - 在编写 jquery 插件时,如何从另一个方法调用我的主要插件方法之一?