Last active
August 29, 2015 14:04
-
-
Save vnys/6f16395d990137604226 to your computer and use it in GitHub Desktop.
How to use the handlebars helpers module
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
## gulpfile: | |
```js | |
var handlebars = require('handlebars'); | |
require('handlebars-helpers').register(handlebars, { | |
marked: { | |
smartypants: true | |
} | |
}); | |
gulp.task('default', function() { | |
var src = fs.readFileSync('src/index.hbs').toString(); | |
var template = handlebars.compile(src); | |
var data = { | |
message: 'test' | |
} | |
file('index.html', template(data)) | |
.pipe(gulp.dest('dist')); | |
}); | |
``` | |
## handlebars: | |
```html | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>test</title> | |
</head> | |
<body> | |
{{>header}} | |
<p>{{message}}</p> | |
{{#markdown}} | |
## helper-test | |
**This** is *markdown* -- with smartypants | |
{{/markdown}} | |
</body> | |
</html> | |
``` | |
## output | |
```html | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>test</title> | |
</head> | |
<body> | |
<header>here be dragons…</header> | |
<p>tjobing</p> | |
<h2 id="helper-test">helper-test</h2> | |
<p><strong>This</strong> is <em>markdown</em> — with smartypants</p> | |
</body> | |
</html> | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment