Using helper arguments and template keyword argume

2019-08-09 05:53发布

I have a template taskList that receives a list of tasks and an options hash as arguments like this:

{{> taskList tasks=taskHelper options=listOptions}}

In this case, the taskHelper returns all existing tasks. Is it possible to pass arguments to the taskHelper in this scenario? For example, if I want to show only done tasks in the template, I would like to do something like this:

{{> taskList tasks=taskHelper 'done' options=listOptions}}

That won't work because the template compiler doesn't treat 'done' as argument for the helper but as a non-keyword argument for the template, resulting in this error message:

Can't have a non-keyword argument after a keyword argument

1条回答
贪生不怕死
2楼-- · 2019-08-09 06:29

meteor < 1.1.1

You can make it work without any changes to your helpers by doing this:

{{#with taskHelper 'done'}}
  {{> taskList tasks=this options=listOptions}}
{{/with}}

meteor >= 1.1.1

Nested helper expressions should solve this problem:

{{> taskList tasks=(taskHelper 'done') options=listOptions}}
查看更多
登录 后发表回答