{"record":{"id":"575a791005c35505","repo":"twigphp/Twig","slug":"the-s-function-is-part-of-the-s-which-is-not-installed","errorCode":null,"errorMessage":"The \"%s\" function is part of the %s, which is not installed/enabled; try running \"composer require %s\".","messagePattern":"The \"(.+?)\" function is part of the (.+?), which is not installed/enabled; try running \"composer require (.+?)\"\\.","errorType":"exception","errorClass":"Twig\\Error\\SyntaxError","httpStatus":null,"severity":"error","filePath":"extra/twig-extra-bundle/MissingExtensionSuggestor.php","lineNumber":30,"sourceCode":"namespace Twig\\Extra\\TwigExtraBundle;\n\nuse Twig\\Error\\SyntaxError;\n\nfinal class MissingExtensionSuggestor\n{\n    public function suggestFilter(string $name): bool\n    {\n        if ($filter = Extensions::getFilter($name)) {\n            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]));\n        }\n\n        return false;\n    }\n\n    public function suggestFunction(string $name): bool\n    {\n        if ($function = Extensions::getFunction($name)) {\n            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]));\n        }\n\n        return false;\n    }\n\n    public function suggestTag(string $name): bool\n    {\n        if ($function = Extensions::getTag($name)) {\n            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]));\n        }\n\n        return false;\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":45,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/twig-extra-bundle/MissingExtensionSuggestor.php#L12-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the composer command from the message, e.g. composer require twig/intl-extra.","Enable the extension: $twig->addExtension(new IntlExtension()); or enable the corresponding bundle.","Compare the function name against documentation to rule out typos.","Register custom functions explicitly if the function is your own."],"exampleFix":"// before\n{{ price|currency_symbol }}\n// after\n$ composer require twig/intl-extra\n$twig->addExtension(new \\Twig\\Extra\\Intl\\IntlExtension());","handlingStrategy":"try-catch","validationCode":"<?php\nuse Twig\\Extra\\TwigExtraBundle\\Extensions;\nif (Extensions::getFilter('trans') && !class_exists(\\Symfony\\Bridge\\Twig\\Extension\\TranslationExtension::class)) {\n    // install/enable the extension before rendering\n}","typeGuard":"<?php\nfunction filterAvailable(Twig\\Environment $twig, string $name): bool\n{\n    return $twig->getFilter($name) !== false;\n}","tryCatchPattern":"<?php\nuse Twig\\Error\\SyntaxError;\ntry {\n    $html = $twig->render('template.twig');\n} catch (SyntaxError $e) {\n    if (str_contains($e->getMessage(), 'composer require')) {\n        error_log($e->getMessage()); // install hinted package\n    }\n    throw $e;\n}","preventionTips":["Require the twig extension packages your templates need (twig/intl-extra, twig/markdown-extra, symfony/twig-bridge, etc.) in composer.json.","Register all installed extra extensions on the Twig Environment during bootstrap.","Add a smoke test that renders representative templates in CI.","Audit template filters against installed extensions when migrating frameworks or trimming dependencies."],"tags":["php","twig","function","missing-extension"],"backgroundTag":"missing-optional-dependency","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}