{"record":{"id":"91b9541b883e78d8","repo":"twigphp/Twig","slug":"the-s-modifier-takes-exactly-one-argument-2-given","errorCode":null,"errorMessage":"The \"%s\" modifier takes exactly one argument (2 given).","messagePattern":"The \"(.+?)\" modifier takes exactly one argument \\(2 given\\)\\.","errorType":"exception","errorClass":"Twig\\Error\\SyntaxError","httpStatus":null,"severity":"error","filePath":"extra/cache-extra/TokenParser/CacheTokenParser.php","lineNumber":45,"sourceCode":"        $key = $this->parser->parseExpression();\n\n        $ttl = null;\n        $tags = null;\n        while ($stream->test(Token::NAME_TYPE)) {\n            $k = $stream->getCurrent()->getValue();\n            if (!\\in_array($k, ['ttl', 'tags'], true)) {\n                throw new SyntaxError(\\sprintf('Unknown \"%s\" configuration.', $k), $stream->getCurrent()->getLine(), $stream->getSourceContext());\n            }\n\n            $stream->next();\n            $stream->expect(Token::OPERATOR_TYPE, '(');\n            $line = $stream->getCurrent()->getLine();\n            if ($stream->test(Token::PUNCTUATION_TYPE, ')')) {\n                throw new SyntaxError(\\sprintf('The \"%s\" modifier takes exactly one argument (0 given).', $k), $line, $stream->getSourceContext());\n            }\n            $arg = $this->parser->parseExpression();\n            if ($stream->test(Token::PUNCTUATION_TYPE, ',')) {\n                throw new SyntaxError(\\sprintf('The \"%s\" modifier takes exactly one argument (2 given).', $k), $line, $stream->getSourceContext());\n            }\n            $stream->expect(Token::PUNCTUATION_TYPE, ')');\n\n            if ('ttl' === $k) {\n                $ttl = $arg;\n            } elseif ('tags' === $k) {\n                $tags = $arg;\n            }\n        }\n\n        $stream->expect(Token::BLOCK_END_TYPE);\n        $body = $this->parser->subparse([$this, 'decideCacheEnd'], true);\n        $stream->expect(Token::BLOCK_END_TYPE);\n\n        $body = new CacheNode($key, $ttl, $tags, $body, $token->getLine());\n\n        return new PrintNode(new RawFilter($body), $token->getLine());\n    }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/cache-extra/TokenParser/CacheTokenParser.php#L27-L63","documentation":"This Twig SyntaxError is thrown when a {% cache %} modifier ('ttl' or 'tags') receives more than one argument. After parsing the first expression, if the parser sees a ',' it knows a second argument was given and reports '2 given' (the tag supports exactly one).","triggerScenarios":"Template like {% cache ttl(60, 120) %} or {% cache tags(['a'], ['b']) %} — comma-separated arguments inside a modifier.","commonSituations":"Developers assuming ttl accepts (value, unit) or tags accepts multiple list arguments, mimicking other template engines' syntax.","solutions":["Pass a single argument per modifier; combine values into one expression if needed.","For multiple tags, pass one array: tags(['a','b']) instead of tags(['a'],['b']).","Split distinct options across the two supported modifiers ttl and tags."],"exampleFix":"// before\n{% cache tags(['a'], ['b']) %}...{% endcache %}\n// after\n{% cache tags(['a','b']) %}...{% endcache %}","handlingStrategy":"validation","validationCode":"if (preg_match('/\\{\\%\\s*cache\\s+(ttl|tags)\\s*\\([^,)]+,/', $template)) {\n    throw new InvalidArgumentException('cache ttl/tags modifiers accept exactly one argument');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $twig->render($template);\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    if (str_contains($e->getMessage(), '(2 given)')) {\n        // combine arguments into a single expression/array\n    }\n    throw $e;\n}","preventionTips":["One argument per modifier: ttl(expr) and tags(expr)","Merge multiple tags into one array literal tags(['a','b'])","Lint templates in CI"],"tags":["twig","template-syntax","argument-count","cache-extension"],"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"}