Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 811 Bytes

templating-with-swig-and-yaml-front-matter.md

File metadata and controls

42 lines (36 loc) · 811 Bytes

Templating with Swig and YAML front-matter

Templating can be setup using gulp-swig and gulp-front-matter:

page.html
---
title: Things to do
todos:
    - First todo
    - Another todo item
    - A third todo item
---
<html>
    <head>
        <title>{{ title }}</title>
    </head>
    <body>
        <h1>{{ title }}</h1>
        <ul>{% for todo in todos %}
          <li>{{ todo }}</li>
        {% endfor %}</ul>
    </body>
</html>
gulpfile.js
var gulp = require('gulp');
var swig = require('gulp-swig');
var frontMatter = require('gulp-front-matter');

gulp.task('compile-page', function() {
  gulp.src('page.html')
      .pipe(frontMatter({ property: 'data' }))
      .pipe(swig())
      .pipe(gulp.dest('build'));
});

gulp.task('default', ['compile-page']);