twigphp/Twig · error · Twig\Error\SyntaxError

The " " filter is part of the , which is not…

Error message

The "%s" filter is part of the %s, which is not installed/enabled; try running "composer require %s".

What it means

MissingExtensionSuggestor::suggestFilter is a Twig runtime-time helper that improves error messages. When a template uses a filter Twig cannot resolve, this method checks the known Extensions map; if the filter belongs to an uninstalled twig extension package it throws a SyntaxError telling the developer exactly which composer package to require.

Solutions

  1. Run the composer command named in the message, e.g. composer require twig/intl-extra.
  2. Register the installed extension on the Environment: $twig->addExtension(new IntlExtension());
  3. Check the filter name for typos against the intended extension's docs.
  4. If the filter is genuinely custom, verify your own extension is added to the Twig Environment.

Example fix

// before
{{ user.name|trans }}
// after
$ composer require symfony/twig-bridge
$twig->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension());
Defensive patterns

Strategy: fallback

Validate before calling

<?php
if (class_exists(\Symfony\Component\String\Inflector\SpanishInflector::class)) {
    $plural = $stringExt->plural($word, 'es');
} else {
    $plural = $word; // or install symfony/string
}

Type guard

<?php
function spanishInflectionAvailable(): bool
{
    return class_exists(\Symfony\Component\String\Inflector\SpanishInflector::class);
}

Try / catch

<?php
use Twig\Error\RuntimeError;
try {
    $plural = $stringExt->plural($word, 'es');
} catch (RuntimeError $e) {
    if (str_contains($e->getMessage(), 'SpanishInflector is not available')) {
        $plural = $word; // fallback
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: A template calls a filter (e.g. trans, inline) registered in Extensions::getFilter(), but the twig extension package providing it is not installed or not registered on the Environment.

Common situations: Using twig trans filters without installing symfony/twig-bridge or twig/intl-extra; moving from full framework to standalone Twig and losing auto-registered extra extensions; typo'd filter names that coincidentally match known extension filters.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13). Data as JSON: /api/errors/81203750927c3c75. Report an issue: GitHub.

Appendix: source

Thrown at extra/twig-extra-bundle/MissingExtensionSuggestor.php:21

/*
 * This file is part of Twig.
 *
 * (c) Fabien Potencier
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Twig\Extra\TwigExtraBundle;

use Twig\Error\SyntaxError;

final class MissingExtensionSuggestor
{
    public function suggestFilter(string $name): bool
    {
        if ($filter = Extensions::getFilter($name)) {
            throw new SyntaxError(\sprintf('The "%s" filter is part of the %s, which is not installed/enabled; try running "composer require %s".', $name, $filter[0], $filter[1]));
        }

        return false;
    }

    public function suggestFunction(string $name): bool
    {
        if ($function = Extensions::getFunction($name)) {
            throw new SyntaxError(\sprintf('The "%s" function is part of the %s, which is not installed/enabled; try running "composer require %s".', $name, $function[0], $function[1]));
        }

        return false;
    }

    public function suggestTag(string $name): bool
    {
        if ($function = Extensions::getTag($name)) {
            throw new SyntaxError(\sprintf('The "%s" tag is part of the %s, which is not installed/enabled; try running "composer require %s".', $name, $function[0], $function[1]));

View on GitHub (pinned to a414c3a491)