codemix / handlebarsphp
Transpiles handlebars templates into native PHP templates.
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-11-24 04:16:29 UTC
README
Note: this is alpha quality software, use at your own risk.
Turns handlebars templates into executable PHP code ahead of time, ships with built in support for Yii 1.x. but allows customisation of output to support different frameworks.
Installation
Install via composer, package name is codemix/handlebarsphp
.
Differences from HandlebarsJS
HandlebarsPHP aims to be compatible with a subset of HandlebarsJS. For performance reasons it compiles the templates ahead of time and this necessitates some restrictions.
-
Since it's impossible to tell whether a tag like
{{foo}}
is a helper or a property at compile time, we assume that its a property. We differentiate helpers by looking for arguments, for example{{foo 1}}
will be interpretted as a function call because it has an argument. This means that it is impossible to call a helper with zero arguments. -
{{@key}}
and{{@index}}
always point to the same variable, becauseforeach
is used for all iteration.