twigphp/Twig · error · SyntaxError
Value for argument "output_strategy" is required for…
Error message
Value for argument "output_strategy" is required for function "render_sandboxed".
What it means
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.
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
Example fix
// before (template)
{{ render_sandboxed('widget.html') }}
// after
{{ render_sandboxed('widget.html', output_strategy='html') }} Defensive patterns
Strategy: validation
Validate before calling
// template source scan before rendering
if (str_contains($templateSource, 'render_sandboxed(')
&& !preg_match('/render_sandboxed\([^)]*output_strategy\s*=/', $templateSource)) {
throw new \RuntimeException('render_sandboxed call missing output_strategy');
} Try / catch
try {
echo $twig->render($template, $ctx);
} catch (\Twig\Error\SyntaxError $e) {
if (str_contains($e->getMessage(), 'output_strategy')) {
// add output_strategy='<strategy>' to the call
}
} Prevention
- 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
When it happens
Trigger: Calling {{ render_sandboxed(template) }} or using the function without passing output_strategy='html' (or another valid strategy name) as a constant named argument.
Common situations: Upgrading Twig where output_strategy became required; copying older template snippets that predate the requirement; assuming a default strategy exists.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The "output_strategy" argument of the "render_sandboxed"…
- Unknown " " configuration.
- The callable passed to the
- Calling the "parent" function outside of a block is…
- Calling the "parent" function on a template that does not…
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/c368c1ea583f9cd4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Node/Expression/FunctionNode/RenderSandboxedFunction.php:30
namespace Twig\Node\Expression\FunctionNode;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Node;
/**
* @internal
*/
final class RenderSandboxedFunction extends FunctionExpression
{
public function compile(Compiler $compiler): void
{
$arguments = $this->getNode('arguments');
$outputStrategyName = self::getOutputStrategyName($arguments);
if (null === $outputStrategyName) {
throw new SyntaxError('Value for argument "output_strategy" is required for function "render_sandboxed".', $this->getTemplateLine(), $this->getSourceContext());
}
$outputStrategy = $arguments->getNode($outputStrategyName);
if (!$outputStrategy instanceof ConstantExpression) {
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());
}
$strategy = $outputStrategy->getAttribute('value');
if (!\is_string($strategy) || '' === $strategy || 'all' === $strategy) {
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());
}
$runtimeArguments = clone $arguments;
$runtimeArguments->removeNode($outputStrategyName);
$this->setNode('arguments', $runtimeArguments);
try {
parent::compile($compiler);
} finally {View on GitHub (pinned to a414c3a491)