Skip to content

Allow Handlebars template partials to accept parameters similar to the `with` operator in Twig.

License

Notifications You must be signed in to change notification settings

UseAllFive/handlebars.partialsWithParameters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

handlebars.partialsWithParameters

Brought to you by Use All Five, Inc.

Author: Justin Anastos <janastos@useallfive.com>
Author URI: [http://www.useallfive.com](http://www.useallfive.com)
Repository: https://github.com/UseAllFive/handlebars.partialsWithParameters

Allow named parameters to be passed to handlebars partials.

Annotated Source

Installation

  • Include lib/handlebars.partialsWithParameters.js before any partials to which you need to pass parameters are rendered.

Usage

  1. Define the Handlebars partial in your JavaScript:

    Handlebars.registerPartial('partialName', partialTemplate);
  2. Call the custom helper created by this module, $, in your template. Note that the partial name must be quoted and sent as a string to the helper.

    {{$ 'partialeName' param1='value1' param2='value2'}}
  3. Use the parameters values by accessing the hash property added to the context of the partial template.

    Partial should be defined like this:

    <div class="test-class">{{ hash.param1 }}</div>
    <div class="test-class">{{ hash.param2 }}</div>

    The output will look like this:

    <div class="test-class">value1</div>
    <div class="test-class">value2</div>

About

Allow Handlebars template partials to accept parameters similar to the `with` operator in Twig.

Resources

License

Stars

Watchers

Forks

Packages

No packages published