同时使用辅助参数和模板关键字参数

Using helper arguments and template keyword arguments at the same time

我有一个模板 taskList 接收任务列表和选项散列作为参数,如下所示:

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

在这种情况下,taskHelper returns 所有现有任务。 在这种情况下是否可以将参数传递给 taskHelper 例如,如果我只想在 done 中显示任务模板,我想做这样的事情:

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

那是行不通的,因为模板编译器不会将 'done' 视为帮助程序的参数,而是将其视为模板的非关键字参数,从而导致此错误消息:

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

流星 < 1.1.1

通过这样做,您可以在不对助手进行任何更改的情况下使其工作:

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

流星 >= 1.1.1

Nested helper expressions 应该可以解决这个问题:

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