Question

I want to add my own twig functionality and to add new twig extension in Symfony 2.

To do that i created these folders: src/Ptracker/TasksBundle/Twig and src/Ptracker/TasksBundle/Twig/Extension and put file myTwigExtension.php in it with this content:

<?php
namespace Ptracker\TasksBundle\Twig\Extension;

class MyTwigExtension extends \Twig_Extension {

public function getFilters() {
    return array(
        'var_dump'   => new \Twig_Filter_Function('var_dump'),
        'linkable'  => new \Twig_Filter_Method($this, 'linkable'),
    );
}

public function linkable($sentence, $expr) {
    return 'it works!!';
}

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

}
?>

Also i added some code to src/Ptracker/TasksBundle/Resources/config/services.yml :

services:
   ptracker.twig.extension:
      class: Ptracker\TasksBundle\Twig\Extension\MyTwigExtension
      tags:
        -  { name: twig.extension }

The point is that i ALWAYS get the same fatal error:

Fatal error: Class 'Ptracker\TasksBundle\Twig\Extension\MyTwigExtension' not found in /home/renat/www/ptracker/app/cache/dev/appDevDebugProjectContainer.php on line 1092 

What am i doing wrong? I've spent several ours to fix this problem, tried to put extension file in different folders, changed namespace.. nothing helps.

Please help me :)

Was it helpful?

Solution

File names are case-sensitive on linux and it doesn't find anything because it tries to load ../MyTwigExtension.php. Rename your file to MyTwigExtension.php.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top