Skip to content

This is a node module to help facilitate registering partials with their respective templating engine.

License

Notifications You must be signed in to change notification settings

Bill4Time/partials-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#partials-loader

Overview

This is a node module to help facilitate registering partials with their respective templating engine. In doing so it creates a namespace from the directory it is loaded from.

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.

Installation

// to install in the local directory
npm install partials-loader

// to install in the local directory and save to the package.json
npm install partials-loader --save

Example Usage

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

Register all files from the templates folder

// 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

Register files from a specific subfolder

// 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

Register files from multiple specific subfolders

// 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

Register multiple file types from multiple specific subfolders

// 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: '/'
                        });

This will result in handlebars having the registered partials:

  • templates/more partials/header
  • templates/more partials/content
  • templates/more partials/footer
  • templates/partials/header
  • templates/partials/content
  • templates/partials/footer

Currently Supported Template Engines

  • Handlebars

If there is a desire for supporting more engines, please post in the issues section of the repository, or feel free to implement it yourself and send a pull request for integration.

About

This is a node module to help facilitate registering partials with their respective templating engine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published