3
votes

Followed http://symfony.com/doc/current/cookbook/templating/twig_extension.html to create my custom Twig filter to be used in my Symfony 2 project.

Everything seems fine but when loading the page, it says:

The filter "tss" does not exist in AppBundle:Default:status.html.twig at line 7

My services.yml:

services:
    app.twig_extension:
        class: AppBundle\Twig\AppExtension
        tags:
            - { name: twig.extension }

My src/AppBundle/Twig/AppExtension.php:

<?php
namespace AppBundle\Twig;

class AppExtension extends \Twig_Extension
{
    public function getFilter()
    {
        return [
            new \Twig_SimpleFilter('tss', [$this, 'tssFilter']),
        ];
    }

    public function tssFilter(\DateTime $timestamp)
    {
        return 'ready';
    }

    public function getName()
    {
        return 'app_extension';
    }
}

Am I missing something here?

Appreciate your advice.

1

1 Answers

3
votes

You have misspelled the method name. Its public function getFilters() not public function getFilter()