jthomas jthomas - 2 months ago 21
Javascript Question

Compile HTML partials with gulp.js

Is there a plugin available for Gulp that does the same thing as Assemble does for Grunt?

I would like to run a task for Gulp that assembles HTML partials, but I cannot find a plugin. Has anyone used one and can you provide a link to it?




UPDATE: 4/21/2016

I just wanted to update this with what I've been using to do this lately. I've been primarily using Twig.js as a frontend templating language with Gulp (you could also use Nunjucks, Swig.js, Handlebars etc.). I've also been using gulp-data when I want to use JSON data for my templates. You can see a quick rundown of how I'm using this approach on a blog post I wrote.

Article: Frontend templating with Gulp and Twig.js

Answer

Yes, you can do it with this plugin called gulp-file-include

Example :

# index.html

<!DOCTYPE html>
<html>
  <body>
  @@include('./view.html')
  @@include('./var.html', {
    "name": "haoxin",
    "age": 12345
  })
  </body>
</html>

# view.html

<h1>view</h1>

# var.html

<label>@@name</label>
<label>@@age</label>