twigphp/Twig · error · Twig\Error\SyntaxError

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

Error message

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

What it means

MissingExtensionSuggestor::suggestTag handles Twig tags. When a template uses a tag Twig cannot parse and that tag belongs to a known extension package (via Extensions::getTag), it throws a SyntaxError instructing the developer which package provides it. Like its siblings, it exists purely to produce better diagnostics.

Solutions

  1. Run the composer command from the message, e.g. composer require symfony/twig-bridge.
  2. Register the extension providing the tag on the Environment (or enable the bundle).
  3. Rewrite the template to avoid the tag (e.g. use the trans filter instead of the tag).
  4. Verify the tag spelling matches the extension's documented syntax.

Example fix

// before
{% trans %}Hello{% endtrans %}
// after
$ composer require symfony/twig-bridge
$twig->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension());
Defensive patterns

Strategy: try-catch

Validate before calling

<?php
use Twig\Extra\TwigExtraBundle\Extensions;
if (Extensions::getFunction('currency_symbol') && !class_exists(\Twig\Extra\Intl\IntlExtension::class)) {
    // require twig/intl-extra before rendering
}

Type guard

<?php
function functionAvailable(Twig\Environment $twig, string $name): bool
{
    return $twig->getFunction($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 contains a tag (e.g. {% trans %}) listed in Extensions::getTag(), but the package registering that tag extension is not installed/enabled.

Common situations: Using {% trans %} or similar tags without symfony/twig-bridge; copying templates from a Symfony app into a plain Twig project; missing bundle registration after a framework upgrade.

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/90c63795b20b7976. Report an issue: GitHub.

Appendix: source

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

            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)