forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close gulpjs#860 PR: Add templating example using Swig and YAML front…
…matter.
- Loading branch information
1 parent
5c8ee6d
commit 346ff9e
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
docs/recipes/templating-with-swig-and-yaml-front-matter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Templating with Swig and YAML front-matter | ||
Templating can be setup using `gulp-swig` and `gulp-front-matter`: | ||
|
||
##### `page.html` | ||
|
||
```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` | ||
|
||
```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']); | ||
``` |