twigphp/Twig · error · Twig\Error\SyntaxError

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

Error message

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

What it means

MissingExtensionSuggestor::suggestFunction mirrors suggestFilter for functions. If a template calls an unknown function that is known to belong to a specific twig-extra extension package, it throws a SyntaxError naming the package to composer require, turning a vague 'unknown function' failure into an actionable install hint.

Solutions

  1. Run the composer command from the message, e.g. composer require twig/intl-extra.
  2. Enable the extension: $twig->addExtension(new IntlExtension()); or enable the corresponding bundle.
  3. Compare the function name against documentation to rule out typos.
  4. Register custom functions explicitly if the function is your own.

Example fix

// before
{{ price|currency_symbol }}
// after
$ composer require twig/intl-extra
$twig->addExtension(new \Twig\Extra\Intl\IntlExtension());
Defensive patterns

Strategy: try-catch

Validate before calling

<?php
use Twig\Extra\TwigExtraBundle\Extensions;
if (Extensions::getFilter('trans') && !class_exists(\Symfony\Bridge\Twig\Extension\TranslationExtension::class)) {
    // install/enable the extension before rendering
}

Type guard

<?php
function filterAvailable(Twig\Environment $twig, string $name): bool
{
    return $twig->getFilter($name) !== false;
}

Try / catch

<?php
use Twig\Error\SyntaxError;
try {
    $html = $twig->render('template.twig');
} catch (SyntaxError $e) {
    if (str_contains($e->getMessage(), 'composer require')) {
        error_log($e->getMessage()); // install hinted package
    }
    throw $e;
}

Prevention

When it happens

Trigger: A template calls a function (e.g. trans, currency_symbol) present in Extensions::getFunction(), while the extension package that registers it is not installed/enabled on the Environment.

Common situations: Rendering templates that use intl or translation functions without twig/intl-extra or symfony/twig-bridge installed; framework migrations where extra bundles were dropped; production builds excluding these packages.

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/575a791005c35505. Report an issue: GitHub.

Appendix: source

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

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]));
        }

        return false;
    }
}

View on GitHub (pinned to a414c3a491)