Skip to content

waynedpj/handlebars-helper-partial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

{{partial}} NPM version

Handlebars helper, alternative to built-in partials. Like Assemble itself, this helper will automatically determine the correct context to use, or a context may be explicitly passed in as a second parameter.

This helper was designed for usage with Assemble, initially as a response to this question on StackOverflow. Feel free to fork it and customize it for your own needs.

If you find a bug or have a feature request, please create an issue.

Installation

Use npm to install the package: npm i handlebars-helper-partial.

Register the helper

The easiest way to register the helper with Assemble is to add the module to devDependencies and keywords in your project's package.json:

{
  "devDependencies": {
    "handlebars-helper-partial": "*"
  },
  "keywords": [
    "handlebars-helper-partial"
  ]
}

Alternatively, to register the helper explicitly in the Gruntfile:

grunt.initConfig({
  assemble: {
    options: {
      // the 'handlebars-helper-partial' npm module must also be listed in
      // devDependencies for assemble to automatically resolve the helper
      helpers: ['handlebars-helper-partial', 'foo/*.js']
    },
    files: {
      'dist/': ['src/templates/*.hbs']
    }
  }
});

Usage Examples

With the helper registered, you may now begin using it in your templates:

{{partial 'foo'}}

Optionally pass in a context as the second parameter:

{{partial 'foo' bar}}

Context

Like Assemble itself, this helper attempts to automatically determine the correct context to use based on the data supplied, but a context can be explicitly passed as a second parameter.

This is how data is merged into the context, in order of precedence:

  1. given context : a context explicitly passed as a second parameter, e.g. {{partial 'foo' bar}}, will win over other contexts.
  2. YAML front matter : YAML front matter of the partial
  3. opts.data[name] : JSON/YAML data file defined in Assemble options.data with a basename matching the name of the partial, e.g {{partial 'foo'}} matches foo.json
  4. this : A context of this usually means either YAML front matter of the "inheriting" page or a block expression wrapping the helper
  5. Assemble options : Custom properties defined in Assemble options
  6. grunt.config.data : Data from grunt.config.data (e.g. pkg: grunt.file.readJSON('package.json'))

Related projects

Besides the handlebars-helpers library, which includes more than 120 helpers, Here are some related projects you might be interested in from the Assemble core team.

  • handlebars-helper-aggregate: {{aggregate}} handlebars helper. inlines content from multiple files optionally using wildcard (globbing/minimatch) patterns. uses YAML front matter as context for each file. optionally pass in a sorting function.
  • handlebars-helper-autolink: {{autolink}} handlebars helper. Generate relative links from the "current page" to other dest pages.
  • handlebars-helper-br: {{br}} Handlebars helper. Adds <br> tags to generated HTML. Great for prototyping.
  • handlebars-helper-compose: {{compose}} handlebars helper. Similar to {{aggregate}}, but this is a block expression helper that inlines content from multiple files differently, extracting YAML front matter to pass to context for each file. Optionally use wildcard (globbing/minimatch) patterns. Accepts compare function as 3rd parameter for sorting inlined files.
  • handlebars-helper-condense: Remove extra newlines from HTML content.
  • handlebars-helper-disqus: {{disqus}} Handlebars helper. Simplifies adding Disqus comments to your site.
  • handlebars-helper-eachitems: {{eachItems}} handlebars helper.
  • handlebars-helper-ghbtns: {{ghbtn}} handlebars helper. Add github buttons (http://ghbtns.com) to your site.
  • handlebars-helper-isActive: {{isactive}} handlebars helper. Adds an 'active' class to the 'current page'. Class can be customized.
  • handlebars-helper-jade: {{jade}} handlebars helper, for converting basic Jade templates to HTML.
  • handlebars-helper-less: {{less}} handlebars helper. This helper allows you to use LESS inside style tags in your HTML. By default, the resulting CSS will be rendered inside the <style>...</style> tags of the rendered HTML, but you may alternatively define a destination path using the dest hash option of the helper.
  • handlebars-helper-lorem: {{lorem}} handlebars helper, for generating lorem lorem placeholder text.
  • handlebars-helper-minify: {{minify}} handlebars helper, for minification of HTML with html-minifier.
  • handlebars-helper-moment: {{moment}} handlebars helper. Combines the powers of Assemble, Handlebars.js and Moment.js into a great helper to master time.
  • handlebars-helper-not: {{not}} handlebars helper. Conditionally render a block if the condition is false. This block helper is really just a semantic alternative to {{isnt}}
  • handlebars-helper-paginate: {{paginate}} handlebars helper. Made for Assemble, the static site generator for Node.js, Grunt.js and Yeoman.
  • handlebars-helper-pkg: {{pkg}} handlebars helper, for retrieving a value from your project's package.json
  • handlebars-helper-post: {{post}} handlebars helper, for including a post, or a list of posts.
  • handlebars-helper-prettify: {{prettify}} handlebars helper, for formatting ("beautifying") HTML, CSS and JavaScript.
  • handlebars-helper-process: {{process}} handlebars helper, for processing raw templates in included content, with the correct context
  • handlebars-helper-rel: Handlebars helper for generating a relative link from the current page to the specified page.
  • handlebars-helper-repeat: {{repeat}} handlebars helper, for duplicating a block of content n times.
  • handlebars-helper-slugify: Convert strings into URL slugs.
  • handlebars-helper-track: {{track}} handlebars helper. Simplify the process of adding Google analytics tracking codes to your web projects.
  • handlebars-helper-twitter: Add {{tweet}} and {{follow}} buttons using handlebars helpers.
  • handlebars-helper-uml: Embed UML diagrams in your handlebars template using www.websequencediagrams.com

Visit assemble.io/plugins for more information about Assemble plugins.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt, and build the documentation with grunt-readme.

Authors

Jon Schlinkert

Brian Woodward

License

Copyright (c) 2013 Jon Schlinkert, contributors. Released under the MIT license


This file was generated by grunt-readme on Tuesday, December 31, 2013.

About

personal hacks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.4%
  • CSS 0.6%