Peter Fox Peter Fox - 5 months ago 51
Twig Question

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 = "".$DocumentId."/".$UserId."/";

return $URL;


And added the filter to the render:


Now the filter is requested in the template:


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...)


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