Download the PHP package xp-forge/handlebars-templates without Composer
On this page you can find all versions of the php package xp-forge/handlebars-templates. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-forge/handlebars-templates
More information about xp-forge/handlebars-templates
Files in xp-forge/handlebars-templates
Package handlebars-templates
Short Description Handlebars templates for XP web frontends
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package handlebars-templates
Handlebars for XP web frontends
Handlebars template engine implementation to be used in conjunction with XP web frontends.
Example
Wiring happens inside your web application:
Templates
The templates live in src/main/handlebars
, their names corresponding to lowercased version of the handlers' names (Home::class
=> home.handlebars
).
Templates support YAML front matter, which can be used to set defaults for template globals. Example:
Fragments
Instead of rendering an entire template, we can render special inline partials we call fragments. They are declared as follows:
...and are rendered by selecting them via fragment() in our handler:
Accessing the URI /listing will render only the <ul>...</ul>
instead of the entire document. These fragments can be used in conjunction with frameworks like htmx, see this gist for an example.
Helpers
On top of the built-in functionality in Handlebars, this library includes the following essential helpers:
encode
: Performs URL-encodingequals
: Tests arguments for equalitycontains
: Tests whether a string or array contains a certain valuesize
: Returns string length or array sizemin
: Returns smallest elementmax
: Returns largest elementany
: Test whether any of the given arguments is truthynone
: Test whether none of the given arguments is truthyall
: Test whether all of the given arguments is truthy
Date handling
The date
helper accepts anything the util.Date
class accepts as constructor argument, or a util.Date
instance itself. To format the date, the format
argument can be used with anything the util.Date::toString()
method accepts. Here are some examples:
Logging
The log
helper will echo the arguments passed to it:
When using the development webserver, this shows the debug page:
In production environments, logs will end up on the server's standard output:
Standalone
To use the template engine by itself, simply instantiate and call its render() method:
This will render the home.handlebars file and return the result as a string.
All versions of handlebars-templates with dependencies
xp-forge/frontend Version ^6.0 | ^5.0 | ^4.0 | ^3.0 | ^2.0
xp-forge/handlebars Version ^9.3
xp-forge/yaml Version ^8.0 | ^7.0 | ^6.0
php Version >=7.0.0