Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Stache custom helper that can be called with or without block

$
0
0
Hi,

In the helper function of can.stache.registerHelper, how do I know if the helper is being called with a block or without a block?
So, if I call the 'myHelper' helper like this:
  1. {{myHelper}}
  2. {{#myHelper}}
  3.   {{message}}
  4. {{/myHelper}}
What would be the test that I would have to call inside the helper function to be able to act differently based on how the helper was called - without block, as in the first call above, or with block, as in the second call?

  1. can.stache.registerHelper('myHelper', function(options) {
  2.   if (<test here>) {
  3.     // helper called without block
  4.     return 'I was called without a block';
  5.   }
  6.   else {
  7.     // helper called with block
  8.     return options.fn({message: 'I was called with block'});
  9.   };
  10. });
Thanks.

Viewing all articles
Browse latest Browse all 3491

Trending Articles