octobercms/october · error · Twig\Error\SyntaxError

When using put, you must have the same number of variables…

Error message

When using put, you must have the same number of variables and assignments.

What it means

Twig syntax error raised in PutTokenParser::parse during template compilation: in direct-assignment mode ({% put name = value %}), the number of target variables on the left does not equal the number of assigned values on the right. The template author must balance the assignment.

Solutions

  1. Make the number of put targets equal the number of assigned expressions
  2. Split the statement into one {% put %} per target
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/cms/twig/tokenparser/PutTokenParser.php:42 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at modules/cms/twig/tokenparser/PutTokenParser.php:42

     * parse a token and returns a node.
     * @return PutNode
     */
    public function parse(TwigToken $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();
        $names = $this->parseAssignmentExpression();

        $capture = false;
        $options = [];

        if ($stream->nextIf(TwigToken::OPERATOR_TYPE, '=')) {
            // Direct assignment mode
            $values = $this->parseMultitargetExpression();
            $stream->expect(TwigToken::BLOCK_END_TYPE);

            if (count($names) !== count($values)) {
                throw new TwigErrorSyntax(
                    'When using put, you must have the same number of variables and assignments.',
                    $stream->getCurrent()->getLine(),
                    $stream->getSourceContext()
                );
            }
        }
        else {
            // Capture mode
            $capture = true;

            if (count($names) > 1) {
                throw new TwigErrorSyntax(
                    'When using put with a block, you cannot have multiple targets.',
                    $stream->getCurrent()->getLine(),
                    $stream->getSourceContext()
                );
            }

View on GitHub (pinned to b608633a7e)