devtheorem/php-handlebars-parser

Parse Handlebars templates to a spec-compliant AST with PHP.

Installs: 69

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/devtheorem/php-handlebars-parser

v1.0.0 2026-02-20 15:20 UTC

This package is auto-updated.

Last update: 2026-02-20 15:38:17 UTC


README

Parse Handlebars templates to a spec-compliant AST with PHP.

Implements the same lexical analysis and grammar specification as Handlebars.js, so any template which can (or cannot) be parsed by Handlebars.js should parse (or error) the same way here.

Note

This project is only a parser. To compile Handlebars templates to native PHP for execution, see PHP Handlebars, which uses this parser.

Installation

composer require devtheorem/php-handlebars-parser

Usage

use DevTheorem\HandlebarsParser\ParserFactory;

$parser = (new ParserFactory())->create();

$template = "Hello {{name}}!";

$result = $parser->parse($template);

If the template contains invalid syntax, an exception will be thrown. Otherwise, $result will contain a DevTheorem\HandlebarsParser\Ast\Program instance.

Whitespace handling

The parser can be created with an optional boolean argument, to support the ignoreStandalone Handlebars compilation option:

$parser = (new ParserFactory())->create(ignoreStandalone: true);

Author

Theodore Brown
https://theodorejb.me