سؤال

I would use this: http://handlebarsjs.com/expressions.html#subexpressions

{{outer-helper (inner-helper 'abc') 'def'}}

But meteor give me an error...there is some solution or workaround for use nested helpers?

thanks!

هل كانت مفيدة؟

المحلول

This is now possible with version 1.2

<p>
    Together we have
    {{pluralize (add myWidgetCount yourWidgetCount), "widget"}}
</p>

https://quip.com/RXFlAk9Rc2xI#dbfACAYxaJX

نصائح أخرى

Nested Helper: If there is a positional argument followed by other (positional or keyword arguments), the first argument is called on the others using the normal helper argument calling convention.

Passing helperB to helperA

{{helperA helperB}}

Passing 'helperB with argument x' to helperA

{{helperA helperB x}}

Passing 'helperB with argument x=false' to helperA

{{helperA helperB x=false}}

Spacebars inclusion and block arguments

https://github.com/meteor/meteor/blob/devel/packages/spacebars/README.md#inclusion-and-block-arguments

i think this part of the docs: http://docs.meteor.com/#ui_registerhelper, and this part http://docs.meteor.com/#template_helpers should answer your question.

Also, meteors template language is called spacebars, although inspired by handlebars, it has some differnces, more to read here: https://github.com/meteor/meteor/blob/devel/packages/spacebars/README.md

This will give us:

// template
<template name="_maybeDiv_wrapInDiv">
  <div>
    {{> UI.contentBlock}}
  </div>
</template>

<template name="_maybeDiv_noop">
  {{> UI.contentBlock}}
</template>

// client code
UI.registerHelper('maybeDiv', function () {
  var isBlock = this.valueOf();

  if (isBlock)
    return Template._maybeDiv_wrapInDiv;
  else
    return Template._maybeDiv_noop;
});

and you can use it like

{{#maybeDiv true}}
  contents
{{/maybeDiv}}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top