3

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.

TaylorR
  • 3,746
  • 5
  • 25
  • 42

1 Answers1

3

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

b.b3rn4rd
  • 8,494
  • 2
  • 45
  • 57
  • 2
    good catch, easy points as soon as you have [the eye](http://fc05.deviantart.net/fs70/f/2012/335/7/9/galaxy_eye_1_by_chaostranquility_nyt-d5mpgie.jpg) 8-). – Alain Tiemblo Jan 27 '15 at 20:53
  • 1
    Yes, agreed. My IDE does not hint me on implementing the function in the inherited interface. – TaylorR Jan 27 '15 at 21:50