{"id":33978727,"url":"https://github.com/bnomei/kirby-handlebars","last_synced_at":"2025-12-13T02:57:12.848Z","repository":{"id":37587763,"uuid":"142620202","full_name":"bnomei/kirby-handlebars","owner":"bnomei","description":"Kirby Component for semantic templates with Handlebars and Mustache","archived":false,"fork":false,"pushed_at":"2025-10-08T13:19:16.000Z","size":432,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-23T09:05:57.837Z","etag":null,"topics":["cache","component","handlebars","handlebars-js","hbs","kirby","kirby-cms","kirby-plugin","kirby5","lightncandy","logic-less","mustache","performance","semantic","template","template-engine"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bnomei.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"bnomei","patreon":"bnomei","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://buymeacoff.ee/bnomei","https://paypal.me/bnomei"]}},"created_at":"2018-07-27T20:19:47.000Z","updated_at":"2025-10-08T13:19:20.000Z","dependencies_parsed_at":"2024-10-03T16:59:18.581Z","dependency_job_id":"8939f13a-c87e-4339-86e2-5f127c6a261e","html_url":"https://github.com/bnomei/kirby-handlebars","commit_stats":{"total_commits":107,"total_committers":3,"mean_commits":"35.666666666666664","dds":"0.23364485981308414","last_synced_commit":"248825c79956f1ad57d65d54436a91a1718ad9c1"},"previous_names":["bnomei/kirby-handlebars"],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/bnomei/kirby-handlebars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby-handlebars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby-handlebars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby-handlebars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby-handlebars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnomei","download_url":"https://codeload.github.com/bnomei/kirby-handlebars/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnomei%2Fkirby-handlebars/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27699132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","component","handlebars","handlebars-js","hbs","kirby","kirby-cms","kirby-plugin","kirby5","lightncandy","logic-less","mustache","performance","semantic","template","template-engine"],"created_at":"2025-12-13T02:57:12.237Z","updated_at":"2025-12-13T02:57:12.843Z","avatar_url":"https://github.com/bnomei.png","language":"PHP","funding_links":["https://github.com/sponsors/bnomei","https://patreon.com/bnomei","https://buymeacoff.ee/bnomei","https://paypal.me/bnomei","https://www.buymeacoffee.com/bnomei"],"categories":[],"sub_categories":[],"readme":"# Kirby Handlebars / Mustache\n\n[![Kirby 5](https://flat.badgen.net/badge/Kirby/5?color=ECC748)](https://getkirby.com)\n![PHP 8.2](https://flat.badgen.net/badge/PHP/8.2?color=4E5B93\u0026icon=php\u0026label)\n![Release](https://flat.badgen.net/packagist/v/bnomei/kirby-handlebars?color=ae81ff\u0026icon=github\u0026label)\n![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby-handlebars?color=272822\u0026icon=github\u0026label)\n[![Discord](https://flat.badgen.net/badge/discord/bnomei?color=7289da\u0026icon=discord\u0026label)](https://discordapp.com/users/bnomei)\n[![Buymecoffee](https://flat.badgen.net/badge/icon/donate?icon=buymeacoffee\u0026color=FF813F\u0026label)](https://www.buymeacoffee.com/bnomei)\n\nKirby Plugin for semantic templates with Handlebars and Mustache\n\n## Installation\n\n- unzip [master.zip](https://github.com/bnomei/kirby-handlebars/archive/master.zip) as folder\n  `site/plugins/kirby-handlebars` or\n- `git submodule add https://github.com/bnomei/kirby-handlebars.git site/plugins/kirby-handlebars` or\n- `composer require bnomei/kirby-handlebars`\n\n## Templates\n\nYou 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.\n\n## Partials\n\nPartials are stored at `/site/template/partials`. Think of them as reusable blocks injected into your handlebars templates **before** they get compiled.\n\n**/site/templates/partials/piece-of-cake.hbs**\n```handlebars\nPiece of {{ cake }}\n```\n\n**/site/templates/call-a-partial.hbs**\n```handlebars\n{{\u003e piece-of-cake }}\n```\n\n**/content/pizza/call-a-partial.txt**\n```markdown\nTitle: 🍕\n```\n\n**/site/controllers/call-a-partial.php**\n```php\n\u003c?php\nreturn function ($site, $page, $kirby) {\n    return ['cake' =\u003e $page-\u003etitle()]; // cake =\u003e 🍕\n};\n```\n\n**localhost:80/pizza**\n```html\nPiece of 🍕\n```\n\n## Data \n\nFor 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.\n\n### Built-in Queries\n\nThe 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.\n\n```handlebars\n\u003carticle id=\"{{ page.slug }}\"\u003e\n  \u003ch2\u003e{{ page.title }}\u003c/h2\u003e\n  {{ page.text }}\n\u003c/article\u003e\n```\n\n```handlebars\n{{ site.title }}\n{{ site.url }}\n{{ page.id }}\n{{ page.title }}\n{{ page.text }}\n{{ page.url }}\n{{ page.slug }}\n{{ page.template }}\n```\n\n### Automatic parsing of queries in all fields\n\nYou can also use queries when providing data from controllers or models. Further more any plain string will be parsed as a query. This allows you to write queries in textarea fields as well.\n\n**/content/blog/unesco-heritage/post.txt**\n```yaml\nTitle: Unesco heritage\n----\nDate: 2017-12-07\n----\nArt: twirling\n----\nText:\nOn {{ page.date.toDate('d.m.Y') }} the Neapolitan art of pizza {{ page.art }} \nhas joined Unesco’s list of intangible heritage.\n```\n\n**/site/templates/post.hbs**\n```handlebars\n\u003carticle id=\"{{ page.slug }}\"\u003e\n  \u003ch2\u003e{{ page.title }}\u003c/h2\u003e\n  {{ page.text }}\n\u003c/article\u003e\n```\n\n**localhost:80/blog/unesco-heritage**\n\n```html\n\u003carticle id=\"unesco-heritage\"\u003e\n  \u003ch2\u003eUnesco heritage\u003c/h2\u003e\n  \u003cp\u003eOn 07.12.2020 the Neapolitan art of pizza twirling \nhas joined Unesco’s list of intangible heritage.\u003c/p\u003e\n\u003c/article\u003e\n```\n\n### Controllers\n\n**/content/home/home.txt**\n```markdown\nTitle: Home\n```\n\n**/site/controllers/home.php**\n```php\n\u003c?php\nreturn function ($site, $page, $kirby) {\n    return [\n        'c'=\u003e 'Cassia',\n        'counting' =\u003e [\n            ['label' =\u003e 1],\n            ['label' =\u003e 2],\n            ['label' =\u003e 3],\n        ],\n    ];\n};\n```\n\n**/site/templates/default.hbs**\n```handlebars\n{{ page.title }} of \u003ci\u003e{{ c }}\u003c/i\u003e.\n\u003cul\u003e\n{{# counting }}\u003cli\u003e{{ label }}\u003c/li\u003e{{/ counting }}\n\u003c/ul\u003e\n```\n\n### Models: Method\n\n**/site/models/home.php**\n```php\n\u003c?php\nclass HomePage extends Page\n{\n    public function handlebarsData(): array\n    {\n        return [\n            'c'=\u003e 'Cassia',\n            'counting' =\u003e [\n                ['label' =\u003e 1],\n                ['label' =\u003e 2],\n                ['label' =\u003e 3],\n            ],\n        ];\n    }\n}\n```\n\n### Models: Extend model from Plugin and define exported methods\n\n```php\n\u003c?php\nclass HomePage extends \\Bnomei\\HandlebarsPage\n{\n    // declare what public methods to export\n    public static $handlebarsData = [\n        'c',        // $this-\u003ec()\n        'counting'  // $this-\u003ecounting()\n    ];\n\n    public function c(): string\n    {\n        return 'Cassia';\n    }\n \n    public function counting(): array\n    {\n        return [\n            ['label' =\u003e 1],\n            ['label' =\u003e 2],\n            ['label' =\u003e 3],\n        ];\n    }\n}\n```\n\n## handlebars()/hbs() helper\n\nMaybe 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.\n\n**/site/templates/render-unto.hbs**\n```handlebars\nRender unto {{ c }} the things that are {{ c }}'s, and unto {{ g }} the things that are {{ g }}'s.\n```\n\n**/site/templates/non-hbs-template.php**\n```php\n\u003c?php\n// echo template 'render-unto'\n// data from site/controllers/home.php merged with custom array\nhbs('render-unto', ['c'=\u003e 'Caesar', 'g'=\u003e'God']);\n```\n\u003e Render unto Caesar the things that are Caesar's, and unto God the things that are God's.\n\n```php\n// return template 'render-unto'\n$string = hbs('render-unto', ['c' =\u003e 'Cat', 'g' =\u003e 'Dog'], true);\necho $string;\n```\n\n\u003e Render unto Cat the things that are Cat's, and unto Dog the things that are Dog's.\n\n## Settings\n\n| bnomei.handlebars.        | Default    | Description               |            \n|---------------------------|------------|---------------------------|\n| component | `true`     | if `false` no templating will be handled by this plugin and you need to use the `hbs()`/`handlebars()` functions. |\n| dir-templates | `callback` | returning `kirby()-\u003eroots()-\u003etemplates()` |\n| dir-partials | `callback` | returning `kirby()-\u003eroots()-\u003etemplates().'/partials'` |\n| extension-input | `hbs`      | |\n| extension-output | `php`      | hbs compiled to php |\n| queries | `[...]`    | an array of predefined queries you can use in your templates |\n\n## Dependencies\n\n- https://github.com/devtheorem/php-handlebars\n\n## Disclaimer\n\nThis plugin is provided \"as is\" with no guarantee. Use it at your own risk and always test it yourself before using it\nin a production environment. If you find any issues,\nplease [create a new issue](https://github.com/bnomei/kirby-handlebars/issues/new).\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nIt is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or\nany other form of hate speech.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby-handlebars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnomei%2Fkirby-handlebars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnomei%2Fkirby-handlebars/lists"}