{{#helper args hashes}}

  • function
can.mustache.helpers.sectionHelper  

Calls a mustache helper function with a block, and optional inverse block.

{{#helper [args...] [hashName=hashValue...]}}BLOCK{{/helper}}

Calls a mustache helper function or a function with a block to render.

The template:

<p>{{#countTo number}}{{num}}{{/countTo}}</p>

Rendered with:

{number: 5}

Will call the countTo helper:

can.mustache.registerHelper('countTo',
  function(number, options){
    var out = [];
    for(var i =0; i < number; i++){
      var docFrag = options.fn({num: i+1});
      out.push( docFrag.textContent );
    }
    return out.join(" ");
});

Results in:

<p>1 2 3 4 5</p>

Parameters

  1. helper {key}

    A key that finds a helper function that is either registered or found within the current or parent context.

  2. args {key | String | Number}Optional Variable

    Space seperated arguments that get passed to the helper function as arguments. If the key's value is a:

  3. hashProperty {String}

    A property name that gets added to a helper options's hash object.

  4. hashValue {key | String | Number}

    A value that gets set as a property value of the helper option argument's hash object.

  5. BLOCK {mustache}

    A mustache template that gets compiled and passed to the helper function as the options argument's fn property.

{{#helper [args...] [hashName=hashValue...]}}BLOCK{{else}}INVERSE{{/helper}}

Calls a mustache helper function or a function with a fn and inverse block to render.

The template:

<p>The bed is
   {{#isJustRight firmness}}
      pefect!
   {{else}}
      uncomfortable.
   {{/justRight}}</p>

Rendered with:

{firmness: 45}

Will call the isJustRight helper:

can.mustache.registerHelper('isJustRight',
  function(number, options){
    if(number > 50){
      return options.fn(this);
    } else {
      return options.inverse(this);
    }
});

Results in:

<p>The bed is uncomfortable.</p>

Parameters

  1. helper {key}

    A key that finds a helper function that is either registered or found within the current or parent context.

  2. args {key | String | Number}Optional Variable

    Space seperated arguments that get passed to the helper function as arguments. If the key's value is a:

  3. hashProperty {String}

    A property name that gets added to a helper options's hash object.

  4. hashValue {key | String | Number}

    A value that gets set as a property value of the helper option argument's hash object.

  5. BLOCK {mustache}

    A mustache template that gets compiled and passed to the helper function as the options argument's fn property.

  6. INVERSE {mustache}

    A mustache template that gets compiled and passed to the helper function as the options argument's inverse property.

Use

Read the use section of {{helper}} to better understand how:

Read how helpers that return functions can be used for rich behavior like 2-way binding.