Download the PHP package bnomei/kirby-handlebars without Composer
On this page you can find all versions of the php package bnomei/kirby-handlebars. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bnomei/kirby-handlebars
More information about bnomei/kirby-handlebars
Files in bnomei/kirby-handlebars
Package kirby-handlebars
Short Description Kirby Component for semantic templates with Handlebars and Mustache
License MIT
Informations about the package kirby-handlebars
Kirby Handlebars / Mustache
Kirby Plugin for semantic templates with Handlebars and Mustache
Installation
- unzip master.zip as folder
site/plugins/kirby-handlebarsor git submodule add https://github.com/bnomei/kirby-handlebars.git site/plugins/kirby-handlebarsorcomposer require bnomei/kirby-handlebars
Templates
You can can have handlebars and php templates in your /site/templates folder. The plugin will be used as template component for all files with hbs extension and default back to Kirbys core template component for the ones written in php.
Partials
Partials are stored at /site/template/partials. Think of them as reusable blocks injected into your handlebars templates before they get compiled.
/site/templates/partials/piece-of-cake.hbs
/site/templates/call-a-partial.hbs
/content/pizza/call-a-partial.txt
/site/controllers/call-a-partial.php
localhost:80/pizza
Data
For the template to render your content, it needs to know which data to use as variables and list in handlebars. This plugin gives you several ways to provide this data, and you can use them all at once. The data from queries will be merged (recursively) with data from controllers and models.
Built-in Queries
The plugin has a few queries built-in. This allows you to use the queried result directly in your handlebar templates. For example, you can use {{ page.title }} in any handlebar template without having to define that value yourself. You can override these in the bnomei.handlebars.queries option.
Optional parsing of queries in data strings
By default, plain strings from content, controllers, and models are rendered as literal data. This prevents editable content from executing Kirby Query methods before Handlebars renders.
If all rendered content is trusted, you can re-enable the old behavior:
With this option enabled, strings can contain Kirby Query placeholders:
/content/blog/unesco-heritage/post.txt
/site/templates/post.hbs
localhost:80/blog/unesco-heritage
Controllers
/content/home/home.txt
/site/controllers/home.php
/site/templates/default.hbs
Models: Method
/site/models/home.php
Models: Extend model from Plugin and define exported methods
handlebars()/hbs() helper
Maybe you just need to parse some handlebars when you create your data, or you do not use the template component at all. For the later disable the component with the bnomei.handlebars.component config setting and just use the provided helper functions. The hbs()/handlebars() take the same parameters as the Kirby snippet() function. This means they echo the result by default but take a third function parameter to enforce returning the value.
/site/templates/render-unto.hbs
/site/templates/non-hbs-template.php
Render unto Caesar the things that are Caesar's, and unto God the things that are God's.
Render unto Cat the things that are Cat's, and unto Dog the things that are Dog's.
Settings
| bnomei.handlebars. | Default | Description |
|---|---|---|
| component | true |
if false no templating will be handled by this plugin and you need to use the hbs()/handlebars() functions. |
| dir-templates | callback |
returning kirby()->roots()->templates() |
| dir-partials | callback |
returning kirby()->roots()->templates().'/partials' |
| extension-input | hbs |
|
| extension-output | php |
hbs compiled to php |
| queries | [...] |
an array of predefined queries you can use in your templates |
| resolve-content-queries | false |
if true, parse Kirby Query placeholders in plain content/controller/model strings |
Dependencies
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
All versions of kirby-handlebars with dependencies
devtheorem/php-handlebars Version ^1.2
getkirby/composer-installer Version ^1.2