标签: gulp-compile-handlebars

如何使用Gulp将部分中的JSON和Handlebars组合成HTML?

我正在使用Handlebars和Gulp构建一个静态站点.这是我的文件夹结构:

app/
    content/
        intro.json
        header.json
        faq.json
        features.json
        footer.json
    templates/
        home.hbs
        partials/
            home-section.hbs
            header.hbs
            footer.hbs
    index.html
Gulpfile.js
Run Code Online (Sandbox Code Playgroud)

home.hbs的内容是这样的:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
</head>
<body>
    {{> header}}
    {{> home-section}}
    {{> home-section}}
    {{> home-section}}
    {{> footer}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我想在传递intro.json,faq.json以及features.json给每个的home-section泛音,并header.jsonheaderfooter.json到页脚.

到目前为止,这是我在Gulpfile中的内容:

var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var rename = require('gulp-rename');

gulp.task('html', function() {
  return gulp.src('./app/templates/*.hbs')
    .pipe(handlebars({}, {
            ignorePartials: true,
            batch: ['./app/templates/partials']
          }))
    .pipe(rename({
            extname: '.html' …
Run Code Online (Sandbox Code Playgroud)

json handlebars.js gulp gulp-compile-handlebars

6
推荐指数
1
解决办法
2163
查看次数

使用Gulp基于Handlebars模板编译部分和降价

我这里有一个Handlebars模板tpage.hbs:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Title</title>
  {{> head}}
</head>
<body>
  {{> home-header}}
  {{{ mdcontents }}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

head并且home-header是偏僻的.

我有一个Markdown文件夹,我想基于这个模板制作HTML页面,在模板中的位置添加.md文件mdcontents.

我有以下Gulpfile:

var gulp = require('gulp');

var handlebars = require('gulp-compile-handlebars');
var HB = require('Handlebars'); // I know I don't need two Handlebars imports, I'm just trying different things at this point
var uglify = require('gulp-uglify');
var markdown = require('gulp-markdown');
var tap = require('gulp-tap');

// ...

gulp.task('markhb', function() {
  return gulp.src('./app/templates/tpage.hbs')
    .pipe(handlebars({}, {
      ignorePartials: false, …
Run Code Online (Sandbox Code Playgroud)

javascript markdown handlebars.js gulp gulp-compile-handlebars

6
推荐指数
1
解决办法
420
查看次数