{"id":16239628,"url":"https://github.com/iantsch/wp-hbs-engine","last_synced_at":"2025-06-14T08:33:12.550Z","repository":{"id":56988221,"uuid":"122685164","full_name":"iantsch/wp-hbs-engine","owner":"iantsch","description":"Renders Handlebars templates within your WordPress Theme/Plugin","archived":false,"fork":false,"pushed_at":"2019-09-16T19:36:37.000Z","size":12,"stargazers_count":4,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T09:06:33.411Z","etag":null,"topics":["handlebars","lightncandy","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":null,"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/iantsch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T23:57:24.000Z","updated_at":"2024-03-23T21:04:32.000Z","dependencies_parsed_at":"2022-08-21T09:40:45.853Z","dependency_job_id":null,"html_url":"https://github.com/iantsch/wp-hbs-engine","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iantsch%2Fwp-hbs-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iantsch%2Fwp-hbs-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iantsch%2Fwp-hbs-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iantsch%2Fwp-hbs-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iantsch","download_url":"https://codeload.github.com/iantsch/wp-hbs-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244463799,"owners_count":20456944,"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","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":["handlebars","lightncandy","wordpress","wordpress-plugin"],"created_at":"2024-10-10T13:44:27.081Z","updated_at":"2025-03-19T16:31:32.700Z","avatar_url":"https://github.com/iantsch.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress Handlebars Engine\n\n[![licence](https://img.shields.io/badge/licence-MIT-blue.svg?style=flat-square)]() [![tag](https://img.shields.io/badge/tag-v0.0.1-lightgrey.svg?style=flat-square)]()\n\nRenders Handlebars/Moustache templates within your WordPress Theme/Plugin. Handlebars rendering is powered by [LightnCandy](https://github.com/zordius/lightncandy). Tested with WordPress 5.2.3\n\n## Installation\nYou can install this (must-use) plugin two ways\n\n### Via Composer\n\nIf you load your dependenies via Composer you can load this plugin with\n\n```sh\n$ php composer require iantsch/wp-hbs-engine\n```\n\n### Via Download\n\nDownload/fork this repository and copy the plugin-folder into `wp-content/plugins/`.\nIf you visit your Plugin section in the `wp-admin` area, activate it and you are good to go.\n\n### Troubleshoots\n\nYou need to load the `zordius/lightncandy` dependency via composer. Install composer and run `$ composer install` in the `wp-content/plugins/wp-hbs-engine` folder.\n\nThe plugin needs a folder with write permissions for caching the handlebar files. It tries to create the folder `wp-content/plugins/wp-hbs-engine/cache`.\n\nThe plugin will try to load partials from the default folder `src/templates/partials` within your current theme. If the folder does not exist please add it (or use the filter hook to adapt).\n\n## Usage\n\nSetup and modify the render engine to your needs in your ``functions.php`` or your plugin\n\n```php\nadd_filter('MBT/Engine/Handlebars/Helpers', function($helpers) {\n  $helpers['__'] = function($string) {\n    return __($string, 'mbt');\n  };\n  $helpers['permalink'] = 'get_permalink';\n  $helpers['content'] = function() {\n    return apply_filters('the_content', get_the_content());\n  };\n  return $helpers;\n});\n```\n\nIn your theme call it like a WordPress function.\n\n```php\nglobal $post;\nwhile (have_posts()){\n  the_post();\n  $data = (array) $post;\n  the_hbs_template('article', $data);\n}\n```\n\nIn your ``article.hbs`` it is [handlebarsjs.com](https://handlebarsjs.com) syntax\n\n```hbs\n\u003ch2\u003e{{this.post_title}}\u003c/h2\u003e\n\u003cdiv\u003e{{{content}}}\u003c/div\u003e\n\u003ca href=\"{{permalink}}\"\u003e{{__ 'Click'}}\u003c/a\u003e\n```\n\n## API\n\n#### get_hbs_template\n| Parameter | Type | Description |\n|---|---|---|\n| ``$template`` | string | template name |\n| ``$data`` | string | associative array with all the needed data for the template |\n| ``$templateDir`` | string \\| boolean | absolutee path to template entry directory, defaults to ``/src/templates/`` in current theme |\n| ``$cacheDir`` | string \\| boolean | absolute path to caching directory, defaults to ``/cache/`` in plugins folder |\n*Returns*: ``$html`` - the rendered HTML output\n\n#### the_hbs_template\n| Parameter | Type | Description |\n|---|---|---|\n| ``$template`` | string | template name |\n| ``$data`` | string | associative array with all the needed data for the template |\n| ``$templateDir`` | string \\| boolean | absolutee path to template entry directory, defaults to ``/src/templates/`` in current theme |\n| ``$cacheDir`` | string \\| boolean | absolute path to caching directory, defaults to ``/cache/`` in plugins folder |\nechoes the rendered HTML output\n## Hooks\n\nThere are several hooks to modify and adapt the render engine\n\n### Filters\n\n#### MBT/Engine/Handlebars/Extension\n| Parameter | Type | Description |\n|---|---|---|\n| ``$extension`` | string | file extension, default: ``hbs`` |\n*Returns*: ``$extension`` - file extension of your handlebar templates\n#### MBT/Engine/Handlebars/Helpers\n| Parameter | Type | Description |\n|---|---|---|\n| ``$helpers`` | array | associative array with callback functions for the implemented helpers |\n| ``$this`` | object | Current instance of Handlebars engine |\n*Returns*: ``$helpers`` - array of handlebars helper\n#### MBT/Engine/Handlebars/Flags\n| Parameter | Type | Description |\n|---|---|---|\n| ``$flags`` | int | bitwise flags used by LightnCandy |\n| ``$this`` | object | Current instance of Handlebars engine |\n*Returns*: ``$flags`` - LightnCandy Flags\n#### MBT/Engine/Handlebars/Partials\n| Parameter | Type | Description |\n|---|---|---|\n| ``$partials`` | array | associative array with the relative path to the partials |\n| ``$this`` | object | Current instance of Handlebars engine |\n*Returns*: ``$partials`` - array of available partials\n#### MBT/Engine/Handlebars/DefaultData\n| Parameter | Type | Description |\n|---|---|---|\n| ``$defaultData`` | array | fallback data for the template |\n| ``$template`` | string | template name |\n*Returns*: ``$defaultData`` - fallback data for the template\n#### MBT/Engine/Handlebars/Data\n| Parameter | Type | Description |\n|---|---|---|\n| ``$data`` | array | associative array with all the needed data for the template |\n| ``$template`` | string | template name |\n*Returns*: ``$data`` - the data for the template\n#### MBT/Engine/Handlebars/Html\n| Parameter | Type | Description |\n|---|---|---|\n| ``$html`` | string | rendered HTML output (with data) |\n| ``$template`` | string | template name |\n| ``$data`` | array | data used to render output |\n*Returns*: ``$html`` - the rendered HTML output\n\n### Actions\n\n#### MBT/Engine/Handlebars/Init\n| Parameter | Type | Description |\n|---|---|---|\n| ``$this`` | object | Current instance of Handlebars engine |\n\n## Credits\n[@iantsch](https://twitter.com/iantsch) - [web developer](https://mbt.wien) behind this and other projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiantsch%2Fwp-hbs-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiantsch%2Fwp-hbs-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiantsch%2Fwp-hbs-engine/lists"}