Symfony2 creates a twig extension

I want to create a simple extension TWIGA ({{imgWidth(...)}})

that calls getimagesize()

and returns width

and height

the image on the server.

I followed the installs you can find here .

When I reload my page I only see a blank page - error.log

tells me that

PHP Fatal error: class 'Fms \ MediaBundle \ Twig \ Extension \ ImgsizeExtension' not found in /var/www/fms/app/cache/dev/appDevDebugProjectContainer.php on line 4773

Service in MediaBundle\Resources\config\services.yml

looks like this:

services:
    twig.extension.imgsize:
        class: Fms\MediaBundle\Twig\Extension\ImgsizeExtension
        tags:
            - name: twig.extension

      

Class :

<?
// src/Fms/MediaBundle/Twig/Extension/ImgsizeExtension.php
namespace Fms\MediaBundle\Twig\Extension;

class ImgsizeExtension extends \Twig_Extension
{
    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('imgsize', array($this, 'imgWidth'))
        );
    }

    public function imgWidth($mediaId = 0, $mediaSize = 'L')
    {
        // ...
        return $mediaId;
    }

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

      

Clearing the cache via the console or manually didn't help either.

+3


source to share


1 answer


Change <?

to <?php

. I copied your code and in this symfony modification I finally found this class.



+2


source







All Articles