Answer the question
In order to leave comments, you need to log in
How to apply a custom filter after your own?
I have several Twig filters of my own. Some of them return markdown, not text or html.
After applying my filter, I have to call another additional filter every time, something like this:
<span>
{{ value|my_filter|markdown }}
</span>
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AdvertExtension extends AbstractExtension
{
public function getFilters():array
{
return [
new TwigFilter('my_filter', [$this, 'my_filter'], ['is_safe' => ['html']]),
];
}
public function my_filter($value): string
{
return sprintf('<b>%s</b>', htmlspecialchars($value));
}
}
<span>
{{ value|my_filter }}
</span>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question