octobercms/october · error · Twig\Error\SyntaxError
The "%s" modifier takes exactly one argument (2 given).
Error message
The "%s" modifier takes exactly one argument (2 given).
What it means
The ttl modifier of the {% cache %} tag takes exactly one argument. After parsing the first expression, the parser checks for a comma; presence of one means at least two arguments were supplied and it throws this SyntaxError (the message always says 2 given, even for more).
Source
Thrown at modules/cms/twig/tokenparser/CacheTokenParser.php:41
$key = $this->parser->parseExpression();
$ttl = null;
while ($stream->test(Token::NAME_TYPE)) {
$k = $stream->getCurrent()->getValue();
if (!in_array($k, ['ttl'], true)) {
throw new SyntaxError(sprintf('Unknown "%s" configuration.', $k), $stream->getCurrent()->getLine(), $stream->getSourceContext());
}
$stream->next();
$stream->expect(Token::OPERATOR_TYPE, '(');
$line = $stream->getCurrent()->getLine();
if ($stream->test(Token::PUNCTUATION_TYPE, ')')) {
throw new SyntaxError(sprintf('The "%s" modifier takes exactly one argument (0 given).', $k), $line, $stream->getSourceContext());
}
$arg = $this->parser->parseExpression();
if ($stream->test(Token::PUNCTUATION_TYPE, ',')) {
throw new SyntaxError(sprintf('The "%s" modifier takes exactly one argument (2 given).', $k), $line, $stream->getSourceContext());
}
$stream->expect(Token::PUNCTUATION_TYPE, ')');
if ($k === 'ttl') {
$ttl = $arg;
}
}
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decideCacheEnd'], true);
$stream->expect(Token::BLOCK_END_TYPE);
$body = new CacheNode($key, $ttl, $body, $token->getLine());
return new PrintNode(new RawFilter($body), $token->getLine());
}
/**View on GitHub (pinned to b608633a7e)
Solutions
- Keep a single expression: {% cache 'sidebar' ttl(3600) %} (minutes).
- Compute composite values in PHP or via a Twig expression before the tag, not as extra arguments.
- Re-save and reload - compile fails until the tag is fixed.
Example fix
{# before #}
{% cache 'sidebar' ttl(3600, 60) %}
{# after #}
{% cache 'sidebar' ttl(3600) %} Defensive patterns
Strategy: validation
Validate before calling
$env = app('twig.environment');
try {
$env->parse($env->tokenize(new \Twig\Source($templateBody, $fileName)));
} catch (\Twig\Error\SyntaxError $e) {
// reject multi-argument ttl(a, b) at lint time
} Try / catch
try {
$env->parse($env->tokenize(new \Twig\Source($body, $name)));
} catch (\Twig\Error\SyntaxError $e) {
// flag 'takes exactly one argument (2 given)' for immediate fix
} Prevention
- The ttl modifier takes one value in minutes - compute composites in PHP.
- Do not transliterate cache()->remember($key, $ttl, $cb) signatures into the tag.
- Lint templates in CI to catch arity mistakes before deploy.
When it happens
Trigger: Writing {% cache 'sidebar' ttl(3600, 60) %} during template compilation - a comma after the TTL expression hits the punctuation check; common when porting cache()->remember($key, $ttl, $callback) muscle memory into the tag.
Common situations: Developers translating PHP cache calls 1:1 into Twig; attempts to pass separate value and unit arguments (ttl(60, 'minutes')).
Related errors
- Unknown "%s" configuration.
- The "%s" modifier takes exactly one argument (0 given).
- Invalid syntax in the component tag. Line %s
- Invalid syntax in the content tag. Line %s
- Invalid syntax in the framework tag. Line %s
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/3733d2b81aa6ccb0.
Report an issue: GitHub.