小编lie*_*ack的帖子

Symfony - Unable to register extension "AppBundle\Twig\Extension\FileExtension" as it is already registered

When I try to implement custom Twig Extension in Symfony2-project, I get following error:

Unable to register extension "AppBundle\Twig\Extension\FileExtension" as it is already registered.

In my app/config/services.yml, I have following:

parameters:
    app.file.twig.extension.class: AppBundle\Twig\Extension\FileExtension

services:
    app.twig.file_extension:
        class: '%app.file.twig.extension.class%'
        tags:
            - { name: 'twig.extension' }
Run Code Online (Sandbox Code Playgroud)

In AppBundle/Twig/Extensions/FileExtension, i have:

<?php

namespace AppBundle\Twig\Extension;

class FileExtension extends \Twig_Extension
{
    /**
     * Return the functions registered as twig extensions
     * 
     * @return array
     */
    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('file_exists', array($this, 'file_exists')),
        ); …
Run Code Online (Sandbox Code Playgroud)

symfony twig twig-extension

6
推荐指数
1
解决办法
4064
查看次数

标签 统计

symfony ×1

twig ×1

twig-extension ×1