octobercms/october · error · Twig\Error\SyntaxError

Invalid syntax in the content tag. Line %s

Error message

Invalid syntax in the content tag. Line %s

What it means

The {% content %} tag parses a content-block name expression (e.g. {% content 'intro.htm' %}) followed by optional name = expression parameters. Any token in the parameter loop that is not a NAME beginning an assignment - a string, number, comma, or operator - throws this SyntaxError with the tag's starting line.

Source

Thrown at modules/cms/twig/tokenparser/ContentTokenParser.php:48

        $nodes = [];
        $paramNames = [];

        // Parse content name (first argument)
        $nodes['__content_name'] = $this->parser->parseExpression();

        // Parse optional parameters
        while (!$stream->test(TwigToken::BLOCK_END_TYPE)) {
            $current = $stream->next();

            if ($current->test(TwigToken::NAME_TYPE)) {
                $paramName = $current->getValue();
                $stream->expect(TwigToken::OPERATOR_TYPE, '=');
                $nodes[$paramName] = $this->parser->parseExpression();
                $paramNames[] = $paramName;
            }
            else {
                throw new TwigErrorSyntax(
                    sprintf('Invalid syntax in the content tag. Line %s', $lineno),
                    $stream->getCurrent()->getLine(),
                    $stream->getSourceContext()
                );
            }
        }

        $stream->expect(TwigToken::BLOCK_END_TYPE);

        // Pass individual nodes instead of wrapping in a 'nodes' array
        return new ContentNode($nodes, $paramNames, $lineno, $this->getTag());
    }

    /**
     * Returns the tag name associated with this token parser.
     * @return string
     */
    public function getTag()

View on GitHub (pinned to b608633a7e)

Solutions

  1. Use only name = expression pairs after the content name: {% content 'intro.htm' name='John' year=2013 %}.
  2. Remove stray commas, strings, or leftover tokens in the tag.
  3. Check the reported line in the page/partials source - the message echoes the tag's start line.

Example fix

{# before: bare second value and missing = #}
{% content 'intro.htm' 'raw' %}

{# after: named parameters only #}
{% content 'intro.htm' name='John' year=2013 %}
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 invalid {% content %} syntax at lint time
}

Try / catch

try {
    $env->parse($env->tokenize(new \Twig\Source($body, $name)));
} catch (\Twig\Error\SyntaxError $e) {
    // 'Invalid syntax in the content tag' - fix params to name = value pairs
}

Prevention

When it happens

Trigger: Writing {% content 'intro.htm' 'raw' %} (bare extra value), {% content 'intro.htm' name 'John' %} (missing =), or {% content 'intro.md' name='John', year=2013 x %} where a stray token follows - the loop's else branch throws. Note the documented syntax separates params with commas, but each param itself must be name = value.

Common situations: Passing extra positional values to content blocks; missing the equals sign; a trailing comma after the last parameter.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/b481caebc714fd42. Report an issue: GitHub.