Nonflavored Prescription Medicine

    docpad-plugin-handlebars

    2.9.0 • Public • Published

    Handlebars Plugin for DocPad

    Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
    GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

    Adds support for the Handlebars templating engine to DocPad

    Convention: .(inlinejs|js|anything).(handlebars|hbs|hb)

    Configuration

    Getting helpers and partials to work

    For the plugin to support helpers and partials, you'll have to add something like the following to your docpad configuration file manually:

    # ... 
    plugins:
        handlebars:
            helpers:
                # Expose docpads 'getBlock' function to handlebars 
                getBlock: (type, additional...) ->
                    additional.pop() # remove the hash object 
                    @getBlock(type).add(additional).toHTML()
            partials:
                title: '<h1>{{document.title}}</h1>'
                goUp: '<a href="#">Scroll up</a>'
    # ... 

    In your handlebars template you will need to use {{{content}}} to prevent handlebars from escaping any html content. You also cannot use helper functions as a parameter to {{#each collection}}, instead you should define a templateData variable and map the name to a @getCollection call e:g:

        sitePages: ->
          @getCollection("pages").toJSON()
    

    Usage as precompiler

    If the document extension is .(inlinejs|js).(handlebars|hbs|hb), the plugin will produce a precompiled template. In this case, you can customise the precompiled template via the following:

    # ... 
    plugins:
        handlebars:
            precompileOpts:
                wrapper: "default"
    # ... 

    Available values for the wrapper option are:

    • "default": Produces a handlebars wrapper like:

      (function() {
          var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
          templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) {
              ...
          })
      })();
    • "amd": Produces a AMD handlebars wrapper like:

      define(['handlebars'], function(Handlebars) {
          var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
          templates['theSlugOfTheFile'] = template(function (Handlebars,depth0,helpers,partials,data) {
              ...
          });
      });
    • "none": Produces a basic wrapper like:

      function (Handlebars,depth0,helpers,partials,data) {
          ...
      }

    Install

    Install this DocPad plugin by entering docpad install handlebars into your terminal.

    History

    Discover the release history by heading on over to the HISTORY.md file.

    Contribute

    Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

    Backers

    Maintainers

    These amazing people are maintaining this project:

    Sponsors

    No sponsors yet! Will you be the first?

    GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

    Contributors

    These amazing people have contributed code to this project:

    Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

    License

    Unless stated otherwise all works are:

    and licensed under:

    Install

    npm i docpad-plugin-handlebars

    DownloadsWeekly Downloads

    5

    Version

    2.9.0

    License

    MIT

    Unpacked Size

    25.5 kB

    Total Files

    8

    Last publish

    Collaborators

    • kizu
    • mmoulton
    • robloach
    • balupton
    • stormpooper
    • bevryme