getgrav/grav · error · SyntaxError

Unexpected end of template. Twig was looking for the followi

Error message

Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)

What it means

Error "Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)" thrown in getgrav/grav.

Source

Thrown at system/src/Grav/Common/Twig/TokenParser/TwigTokenParserSwitch.php:96

                    $stream->expect(Token::BLOCK_END_TYPE);
                    $body = $this->parser->subparse($this->decideIfFork(...));
                    $cases[] = new class([
                        'values' => new Nodes($values),
                        'body' => $body
                    ]) extends Node {};
                    break;

                case 'default':
                    $stream->expect(Token::BLOCK_END_TYPE);
                    $default = $this->parser->subparse($this->decideIfEnd(...));
                    break;

                case 'endswitch':
                    $end = true;
                    break;

                default:
                    throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $lineno), -1);
            }
        }

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

        return new TwigNodeSwitch($name, new Nodes($cases), $default, $lineno, $this->getTag());
    }

    /**
     * Decide if current token marks switch logic.
     *
     * @param Token $token
     * @return bool
     */
    public function decideIfFork(Token $token): bool
    {
        return $token->test(['case', 'default', 'endswitch']);
    }

View on GitHub (pinned to 6040efed04)

When it happens

Trigger: Thrown at system/src/Grav/Common/Twig/TokenParser/TwigTokenParserSwitch.php:96 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of getgrav/grav@6040efed04 (2026-08-17). Data as JSON: /api/errors/fdce796b1e3495c8. Report an issue: GitHub.