Partials loader is a node module to faciliate the registering of partials with a respective template engine.
npm install partials-loader#partials-loader
This means that when using this module you will be able to reference partials in your templates directory by providing the relative path from your template directory to the partial being loaded and handlebars will be aware of it.
First, pretend that we have a folder called
/Users/username/node project/
And in this folder there is this directory structure
/Users/username/node project/
|__templates
|__example.hbs
|__index.hbs
|__more partials
|__header.hbs
|__content.html
|__footers.hbs
|__partials
|__header.hbs
|__content.html
|__footers.hbs
javascript
// First load your engine and the partials-loader
var handlebars = require('handlebar');
var partialLoader = require('partials-loader');// This registers every handlebar file
partialLoader.handlebars({ template_engine_reference: handlebars,
template_root_directories: '/Users/username/node project/templates',
partials_directory_names: '.',
template_extensions: 'hbs',
delimiter_symbol: '/'
});
`
This will result in handlebars having the registered partials:
- templates/example
- templates/index
- templates/more partials/header
- templates/more partials/footer
- templates/partials/header
- templates/partials/footer$3
`javascript
// First load your engine and the partials-loader
var handlebars = require('handlebar');
var partialLoader = require('partials-loader');// This registers every handlebar file in the partials folder
partialLoader.handlebars({ template_engine_reference: handlebars,
template_root_directories: '/Users/username/node project/templates',
partials_directory_names: 'partials',
template_extensions: 'hbs',
delimiter_symbol: '/'
});
`
This will result in handlebars having the registered partials:
- templates/partials/header
- templates/partials/footer$3
`javascript
// First load your engine and the partials-loader
var handlebars = require('handlebar');
var partialLoader = require('partials-loader');// This registers every handlebar file in the specified folders
partialLoader.handlebars({ template_engine_reference: handlebars,
template_root_directories: '/Users/username/node project/templates',
partials_directory_names: ['more partials', 'partials'],
template_extensions: 'hbs',
delimiter_symbol: '/'
});
`
This will result in handlebars having the registered partials:
- templates/more partials/header
- templates/more partials/footer
- templates/partials/header
- templates/partials/footer$3
`javascript
// First load your engine and the partials-loader
var handlebars = require('handlebar');
var partialLoader = require('partials-loader');// This registers every handlebar file in the specified folders
partialLoader.handlebars({ template_engine_reference: handlebars,
template_root_directories: '/Users/username/node project/templates',
partials_directory_names: ['more partials', 'partials'],
template_extensions: ['hbs', 'html'],
delimiter_symbol: '/'
});
``