vitkarpov / grunt-nunjucks-2-html

Compiles nunjucks templates *right* into HTML
MIT License
35 stars 11 forks source link

Relative Paths in includes #23

Closed mkra closed 9 years ago

mkra commented 9 years ago

It seems to be impossible to use includes with relative paths e.g. {% include "../../component/header/header.tpl" %} in index.html

/component
    /header
        header.tpl
/templates
    index.html
    /tpl
        index.tpl

Gruntfile.js

module.exports = {
    options: {
        data: grunt.file.readJSON('data.json'),
        paths: ['templates/tpl']
    },
    render: {
        files: [
            {
                expand: true,
                cwd: 'templates/tpl',
                src: '**.tpl',
                dest: 'templates',
                ext: '.html'
            }
        ]
    }
};
vitkarpov commented 9 years ago

@mkra It seems you can specify several paths:

paths: ['templates', 'component']

and then just use include relative to the component folder

{% include header/header.tpl %}
mkra commented 9 years ago

@vitkarpov thanks, that works.

vitkarpov commented 9 years ago

Great! :+1: