4
votes

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

1

1 Answers

11
votes

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