{"record":{"id":"c368c1ea583f9cd4","repo":"twigphp/Twig","slug":"value-for-argument-output-strategy-is-required-for-function","errorCode":null,"errorMessage":"Value for argument \"output_strategy\" is required for function \"render_sandboxed\".","messagePattern":"Value for argument \"output_strategy\" is required for function \"render_sandboxed\"\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/Node/Expression/FunctionNode/RenderSandboxedFunction.php","lineNumber":30,"sourceCode":"namespace Twig\\Node\\Expression\\FunctionNode;\n\nuse Twig\\Compiler;\nuse Twig\\Error\\SyntaxError;\nuse Twig\\Node\\Expression\\ConstantExpression;\nuse Twig\\Node\\Expression\\FunctionExpression;\nuse Twig\\Node\\Node;\n\n/**\n * @internal\n */\nfinal class RenderSandboxedFunction extends FunctionExpression\n{\n    public function compile(Compiler $compiler): void\n    {\n        $arguments = $this->getNode('arguments');\n        $outputStrategyName = self::getOutputStrategyName($arguments);\n        if (null === $outputStrategyName) {\n            throw new SyntaxError('Value for argument \"output_strategy\" is required for function \"render_sandboxed\".', $this->getTemplateLine(), $this->getSourceContext());\n        }\n\n        $outputStrategy = $arguments->getNode($outputStrategyName);\n        if (!$outputStrategy instanceof ConstantExpression) {\n            throw new SyntaxError('The \"output_strategy\" argument of the \"render_sandboxed\" function must be a non-empty literal string other than \"all\".', $outputStrategy->getTemplateLine(), $outputStrategy->getSourceContext());\n        }\n\n        $strategy = $outputStrategy->getAttribute('value');\n        if (!\\is_string($strategy) || '' === $strategy || 'all' === $strategy) {\n            throw new SyntaxError('The \"output_strategy\" argument of the \"render_sandboxed\" function must be a non-empty literal string other than \"all\".', $outputStrategy->getTemplateLine(), $outputStrategy->getSourceContext());\n        }\n\n        $runtimeArguments = clone $arguments;\n        $runtimeArguments->removeNode($outputStrategyName);\n        $this->setNode('arguments', $runtimeArguments);\n        try {\n            parent::compile($compiler);\n        } finally {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Expression/FunctionNode/RenderSandboxedFunction.php#L12-L48","documentation":"render_sandboxed() renders an included template with output escaping controlled by the 'output_strategy' argument. During compilation, Twig resolves the output strategy name from the arguments node; if it cannot find any output_strategy argument at all, compilation fails with this SyntaxError because the strategy is mandatory.","triggerScenarios":"Calling {{ render_sandboxed(template) }} or using the function without passing output_strategy='html' (or another valid strategy name) as a constant named argument.","commonSituations":"Upgrading Twig where output_strategy became required; copying older template snippets that predate the requirement; assuming a default strategy exists.","solutions":["Add output_strategy='html' (or the desired strategy) to the render_sandboxed call","Consult the render_sandboxed documentation for valid strategy values","Audit templates that use render_sandboxed after upgrading Twig","If strategy should vary at runtime, ensure a constant fallback is present for compile-time resolution"],"exampleFix":"// before (template)\n{{ render_sandboxed('widget.html') }}\n// after\n{{ render_sandboxed('widget.html', output_strategy='html') }}","handlingStrategy":"validation","validationCode":"// template source scan before rendering\nif (str_contains($templateSource, 'render_sandboxed(')\n    && !preg_match('/render_sandboxed\\([^)]*output_strategy\\s*=/', $templateSource)) {\n    throw new \\RuntimeException('render_sandboxed call missing output_strategy');\n}","typeGuard":null,"tryCatchPattern":"try {\n    echo $twig->render($template, $ctx);\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    if (str_contains($e->getMessage(), 'output_strategy')) {\n        // add output_strategy='<strategy>' to the call\n    }\n}","preventionTips":["Always pass output_strategy explicitly to render_sandboxed","After Twig upgrades, grep templates for render_sandboxed and verify required args","Document the mandatory argument in your team's template style guide"],"tags":["twig","sandbox","required-argument","compile-time"],"backgroundTag":"missing-required-argument","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"}