Using helper arguments and template keyword arguments at the same time

a 夏天 提交于 2019-12-13 02:26:43

问题


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:


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}}


来源:https://stackoverflow.com/questions/31441032/using-helper-arguments-and-template-keyword-arguments-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!