twigphp/Twig · error · SyntaxError
Value for argument " " is required for " ".
Error message
Value for argument "%s" is required for %s "%s".
What it means
For non-variadic callables with no named arguments, extractArguments() checks that the number of supplied arguments covers the required parameters of the underlying PHP callable (offset by hidden internal required arguments). When too few arguments are given, it throws a SyntaxError naming the first missing required argument, the callable type, and its name.
Solutions
- Supply the missing required argument named in the message at the indicated position.
- Give the missing argument a default value in the underlying PHP callable if it is genuinely optional.
- Check the extension's registered callable signature and update the template call to match it.
Example fix
{# before #}
{{ range(5) }}
{# after (if start is required) #}
{{ range(0, 5) }} Defensive patterns
Strategy: validation
Try / catch
try {
return $twig->render($name, $ctx);
} catch (Twig\Error\SyntaxError $e) {
if (preg_match('/Value for argument "(.+?)" is required/', $e->getMessage(), $m)) {
throw new DomainException('Template call missing required argument "'.$m[1].'" at line '.$e->getTemplateLine(), 0, $e);
}
throw $e;
} Prevention
- Check each custom Twig callable's signature against all template call sites when adding required parameters.
- Add default values to parameters that are genuinely optional.
- Lint templates in CI so missing-argument mistakes fail before deployment.
When it happens
Trigger: A template calls a Twig function/filter/test with fewer positional arguments than the mapped PHP callable requires, e.g. {{ max() }} or {{ range(1) }} when the callable demands more parameters.
Common situations: Typos or refactorings that drop an argument; custom Twig extensions exposing PHP functions whose required arity exceeds what templates pass; upgrading an extension where a parameter gained a required argument.
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
- Calling the "parent" function outside of a block is…
- Calling the "parent" function on a template that does not…
- You cannot assign a value to
- A template that extends another one cannot include content…
- Positional arguments cannot be used after named arguments…
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/cfa19f59ac02c1b6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Util/CallableArgumentsExtractor.php:61
$extractedArgumentNameMap = [];
$named = false;
foreach ($arguments as $name => $node) {
if (!\is_int($name)) {
$named = true;
} elseif ($named) {
throw new SyntaxError(\sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $this->twigCallable->getType(), $this->twigCallable->getName()), $this->node->getTemplateLine(), $this->node->getSourceContext());
}
$extractedArguments[$normalizedName = $this->normalizeName($name)] = $node;
$extractedArgumentNameMap[$normalizedName] = $name;
}
if (!$named && !$this->twigCallable->isVariadic()) {
$min = $this->twigCallable->getMinimalNumberOfRequiredArguments();
if (\count($extractedArguments) < $this->rc->getReflector()->getNumberOfRequiredParameters() - $min) {
$argName = $this->toSnakeCase($this->rc->getReflector()->getParameters()[$min + \count($extractedArguments)]->getName());
throw new SyntaxError(\sprintf('Value for argument "%s" is required for %s "%s".', $argName, $this->twigCallable->getType(), $this->twigCallable->getName()), $this->node->getTemplateLine(), $this->node->getSourceContext());
}
return $extractedArguments;
}
if (!$callable = $this->twigCallable->getCallable()) {
if ($named) {
throw new SyntaxError(\sprintf('Named arguments are not supported for %s "%s".', $this->twigCallable->getType(), $this->twigCallable->getName()));
}
throw new SyntaxError(\sprintf('Arbitrary positional arguments are not supported for %s "%s".', $this->twigCallable->getType(), $this->twigCallable->getName()));
}
[$callableParameters, $isPhpVariadic] = $this->getCallableParameters();
$arguments = [];
$callableParameterNames = [];
$missingArguments = [];
$optionalArguments = [];View on GitHub (pinned to a414c3a491)