{"record":{"id":"c29066fce705d1e6","repo":"octobercms/october","slug":"invalid-syntax-in-the-component-tag-line-s","errorCode":null,"errorMessage":"Invalid syntax in the component tag. Line %s","messagePattern":"Invalid syntax in the component tag\\. Line (.+?)","errorType":"exception","errorClass":"Twig\\Error\\SyntaxError","httpStatus":null,"severity":"error","filePath":"modules/cms/twig/tokenparser/ComponentTokenParser.php","lineNumber":53,"sourceCode":"        while (!$stream->test(TwigToken::BLOCK_END_TYPE)) {\n            $current = $stream->next();\n\n            if ($current->test(TwigToken::NAME_TYPE)) {\n                $paramName = $current->getValue();\n\n                // Support hyphenated attribute names like `data-testid` and `aria-label`.\n                // Twig tokenizes them as NAME `-` NAME ..., so consume the pieces until `=`.\n                while ($stream->test(TwigToken::OPERATOR_TYPE, '-')) {\n                    $stream->next();\n                    $paramName .= '-' . $stream->expect(TwigToken::NAME_TYPE)->getValue();\n                }\n\n                $stream->expect(TwigToken::OPERATOR_TYPE, '=');\n                $nodes[$paramName] = $this->parser->parseExpression();\n                $paramNames[] = $paramName;\n            }\n            else {\n                throw new TwigErrorSyntax(\n                    sprintf('Invalid syntax in the component tag. Line %s', $lineno),\n                    $stream->getCurrent()->getLine(),\n                    $stream->getSourceContext()\n                );\n            }\n        }\n\n        $stream->expect(TwigToken::BLOCK_END_TYPE);\n\n        // Pass nodes directly without wrapping inside 'nodes'\n        return new ComponentNode($nodes, $paramNames, $lineno, $this->getTag());\n    }\n\n    /**\n     * getTag name associated with this token parser.\n     * @return string The tag name\n     */\n    public function getTag()","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/twig/tokenparser/ComponentTokenParser.php#L35-L71","documentation":"The {% component %} tag parses a component name expression, then zero or more parameter assignments of the form name = expression (hyphenated names like data-testid are supported). Any token that is not a NAME starting an assignment - a bare string, a number, or a stray operator - throws this SyntaxError with the tag's starting line.","triggerScenarios":"Writing {% component 'blogPost' 'sidebar' %} (second value without name =), {% component 'blogPost' 123 %}, or {% component alias='x' %} where the leading component name expression is malformed - the loop hits a non-NAME token and throws.","commonSituations":"Assuming positional arguments like Twig functions; missing the = between parameter and value; trailing commas or leftover characters after the last parameter.","solutions":["Write parameters as assignments only: {% component 'blogPost' alias='sidebar' %}.","Pass any non-assignment value as part of the component name expression or set it on the component's properties instead.","Remove stray tokens (commas, quotes, numbers) after the parameter list."],"exampleFix":"{# before: positional second argument - not a NAME = pair #}\n{% component 'blogPost' 'sidebar' %}\n\n{# after: named assignment #}\n{% component 'blogPost' alias='sidebar' %}","handlingStrategy":"validation","validationCode":"$env = app('twig.environment');\ntry {\n    $env->parse($env->tokenize(new \\Twig\\Source($templateBody, $fileName)));\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    // reject invalid {% component %} syntax at lint time\n}","typeGuard":null,"tryCatchPattern":"try {\n    $env->parse($env->tokenize(new \\Twig\\Source($body, $name)));\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    // 'Invalid syntax in the component tag' - fix params to name = value pairs\n}","preventionTips":["Use only name = expression pairs after the component name (hyphenated names allowed).","No positional arguments in {% component %}.","Lint templates containing component tags before deploying."],"tags":["twig","syntax-error","component-tag","template"],"backgroundTag":"template-syntax-error","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}