Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twig filter multiple parameters

I'm trying to create a specific twig filter that can handle 2 parameters.

$documentURL = new Twig_SimpleFilter('documentURL', function($DocumentId, $UserId){

    $URL = "http://example.example.com/start/".$DocumentId."/".$UserId."/";

    return $URL;

});

And added the filter to the render:

$twig->addFilter($documentURL);

Now the filter is requested in the template:

{{documentURL(booking.docId, user.id)}}

However, i'm getting an error that the function doesn't exist. Quitte strange... Because it does exist and it is included. The same way like my other 15 filters.

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The function "documentURL" does not exist in "profile.html" at line 78'

Am I requesting the filter the wrong way? (Probably yes...)

like image 291
Peter Fox Avatar asked Dec 20 '22 17:12

Peter Fox


1 Answers

You tried to call your filter like a function. There is a difference between twig filters and functions. You should call the filter like {{ value|filterName(param) }}. So in your case:

{{ booking.docId|documentURL(user.id)}}
like image 196
NHG Avatar answered Dec 24 '22 01:12

NHG