8

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 Answer 1

16

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.