patrickkettner / grunt-compile-handlebars

grunt plugin to compile static html from a handlebars plugin
MIT License
115 stars 29 forks source link

Includes #53

Closed iamdriz closed 8 years ago

iamdriz commented 9 years ago

How do I use includes (partials) with this module?

So basically I want to export a file called index.html from index.handlebars which will have a header and footer that are stored in _header.handlebars and _footer.handlebars.

I have this in my Gruntfile.js

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    compile-handlebars: {
        files: [{
            src: 'src/index.handlebars',
            dest: 'dist/index.html'
        }]
    }
});

What should be inside the index.handlebars to include them? As usually you have to use the Handlebars compile function to create partials... does this support something like what you can do in Jade and just do an include(_header) ?

patrickkettner commented 9 years ago

You add partials to your config object then reference them like you normally would.

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    compile-handlebars: {
        files: [{
            src: 'src/index.handlebars',
            dest: 'dist/index.html'
        }],
        partials: ['partials/_*.handlebars']
    }
});
{{> _header}}
CONTENT!
{{> _footer}}