Executing closure on Twig

前端 未结 3 1446
梦谈多话
梦谈多话 2021-01-13 08:51

I\'m trying to execute a closure that resides inside an array on a Twig template. Below you could find a simplified snippet of which I\'m trying:


//Sym         


        
3条回答
  •  不要未来只要你来
    2021-01-13 09:36

    If you are using a closure you can use the the call method of the closure

    http://php.net/manual/en/closure.call.php

    You will end up with something like this

    {{ funcs.conditional.call(obj, obj) }}
    

    Since the first parameter must be the object that 'this' will refer too I am passing the same object as the first parameter.

    No twig extension and no extra PHP code to do ;)

提交回复
热议问题