core icon indicating copy to clipboard operation
core copied to clipboard

Anonymous function in template

Open touskar opened this issue 8 years ago • 5 comments

I used the filter function on an object collection, but when I pass it an anonymous function in parameter I get an error during the rendering process of the page. {{ items.filter((item) => return item.value > 5) }} I am obliged to declare the anonymous function in the controller, then pass it in the parameters of the view.

async ({view}) => {
  return view.render('template', {
    filterFn: (item) => {
      return item.lengh > 0
    }
  })
}

And then : {{ items.filter(filterFn) }}

touskar avatar Jan 23 '18 08:01 touskar

Ues templates are not Javascript files, and hence an anonymous function is not allowed.

thetutlage avatar Jan 23 '18 10:01 thetutlage

Okey so I can't pass general javascript expression to edge template. Thanks

touskar avatar Jan 23 '18 11:01 touskar

You can always use view presenters to achieve this kind of thing.

RomainLanz avatar Jan 23 '18 12:01 RomainLanz

Okey. Thanks

touskar avatar Jan 24 '18 12:01 touskar

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Mar 11 '20 08:03 lock[bot]