{"id":22044787,"url":"https://github.com/cradlephp/handlebars","last_synced_at":"2025-05-08T05:53:49.813Z","repository":{"id":56958565,"uuid":"124773208","full_name":"CradlePHP/Handlebars","owner":"CradlePHP","description":"Ultra fast PHP7 implementation of handlebars.js","archived":false,"fork":false,"pushed_at":"2021-03-14T07:48:50.000Z","size":72,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-08T05:53:44.284Z","etag":null,"topics":["cradle","cradlephp","handlebars","template-engine","v2","v3-prototype"],"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/CradlePHP.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-03-11T15:57:46.000Z","updated_at":"2024-12-18T08:17:46.000Z","dependencies_parsed_at":"2022-08-21T05:10:24.616Z","dependency_job_id":null,"html_url":"https://github.com/CradlePHP/Handlebars","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CradlePHP%2FHandlebars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CradlePHP%2FHandlebars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CradlePHP%2FHandlebars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CradlePHP%2FHandlebars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CradlePHP","download_url":"https://codeload.github.com/CradlePHP/Handlebars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253009850,"owners_count":21839713,"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":["cradle","cradlephp","handlebars","template-engine","v2","v3-prototype"],"created_at":"2024-11-30T13:08:33.659Z","updated_at":"2025-05-08T05:53:49.792Z","avatar_url":"https://github.com/CradlePHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# handlebars.php\nUltra fast PHP7 implementation of handlebars.js\n\n[![Travis CI](https://travis-ci.org/CradlePHP/Handlebars.svg?branch=master)](https://travis-ci.org/CradlePHP/handlebars)\n[![Coverage Status](https://coveralls.io/repos/github/CradlePHP/Handlebars/badge.svg?branch=master)](https://coveralls.io/github/CradlePHP/handlebars?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/cradlephp/handlebars/v/stable)](https://packagist.org/packages/cradlephp/handlebars)\n[![Total Downloads](https://poser.pugx.org/cradlephp/handlebars/downloads)](https://packagist.org/packages/cradlephp/handlebars)\n[![Latest Unstable Version](https://poser.pugx.org/cradlephp/handlebars/v/unstable)](https://packagist.org/packages/cradlephp/handlebars)\n[![License](https://poser.pugx.org/cradlephp/handlebars/license)](https://packagist.org/packages/cradlephp/handlebars)\n\n## Install\n\n```bash\n$ composer install cradlephp/handlebars\n```\n \n\u003ca name=\"intro\"\u003e\u003c/a\u003e\n## Introduction\n\nPHP Handlebars and JS interface to match with compile time helper support and super nice compile\ntime error reporting. This version of Handlebars is based on caching the compiled templates and\ninherently made the overall compile times faster. Loading at ~50ms uncached and ~30ms cached.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Basic Usage\n\n#### Rendering\n\n```php\nuse Cradle\\Handlebars\\HandlebarsHandler as Handlebars;\n$handlebars = new Handlebars();\n$template = $handlebars-\u003ecompile('{{foo}} {{bar}}');\n\necho $template(['foo' =\u003e 'BAR', 'bar' =\u003e 'ZOO']);\n```\n\n#### Registering Helpers\n\n```\n$handlebars-\u003eregisterHelper('bar', function($options) {\n    return 'ZOO';\n});\n\n$template = $handlebars-\u003ecompile('{{foo}} {{bar}}');\n\necho $template(['foo' =\u003e 'BAR']);\n```\n\n#### Registering Partials\n\n```\n$handlebars-\u003eregisterPartial('bar', 'zoo');\n$template = $handlebars-\u003ecompile('{{foo}} {{\u003e bar}}');\n\necho $template(['foo' =\u003e 'BAR']);\n```\n\n----\n\n\u003ca name=\"features\"\u003e\u003c/a\u003e\n## Features\n\n - PHP API - designed to match the handlebars.js documentation\n    - registerHelper() - Matches exactly what you expect from handlebars.js (except it's PHP syntax)\n    - registerPartial() - accepts strings and functions as callbacks\n    - Literals like `{{./foo}}` and `{{../bar}}` are evaluated properly\n    - Comments like `{{!-- Something --}}` and `{{! Something }}` supported\n    - Trims like `{{~#each}}` and `{{~foo~}}` supported\n    - Mustache backwards compatibility `{{#foo}}{{this}}{{/foo}}`\n    - Tokenizer helpers to optimize custom code generation to cache\n    - Event handlers for unknown helpers and unknown partials\n - Default Helpers matching handlebars.js\n     - each - and `{{#each foo as |value, key|}}`\n         - Please note that there is an issue with `each` being slow depending on the size of the object\n         - We need help optimizing this\n     - with\n     - unless\n     - if\n\n\u003ca name=\"defeatures\"\u003e\u003c/a\u003e\n## De-Features (or whatever the opposite of features is)\n\n - Does not support file templates.\n     - You need to load them up and pass it into Handlebars.\n     - If this is a problem you should consider other Handlebars PHP libraries\n     - You can always create a helper for this\n     - This de-feature will be considered upon requests ( create an issue :) )\n - Partial Failover\n     - Something we haven't had a chance to come around doing yet as we did not have a need\n     - This de-feature will be considered upon requests ( create an issue :) )\n - Safe String/Escaping\n     - PHP has functions that can turn a string \"safe\".\n     - We didn't want to create something that already exists in other contexts\n     - This de-feature will be considered upon requests ( create an issue :) )\n - Utils\n     - PHP has functions that support most of the listed Utils in handlebars.js\n     - We didn't want to create something that already exists in other contexts\n     - This de-feature will be considered upon requests ( create an issue :) )\n - Dynamic Partials\n     - At the bottom of our pipe\n     - because of it's difficulty to recreate\n     - and practicality\n     - This de-feature will be considered upon requests ( create an issue :( )\n - Inline Partials\n     - TODO\n - Decorators\n     - TODO\n - Frames\n     - TODO\n\n----\n\n\u003ca name=\"production\"\u003e\u003c/a\u003e\n## Production Ready\n\nWhen your templates are ready for a production (live) environment, it is recommended that caching be used. To enable cache:\n\n - Create a cache folder and make sure permissions are properly set for handlebars to write files to it.\n - Enable cache by using `$handlebars-\u003esetCache(__DIR__.'/your/cache/folder/location');`\n - If the folder location does not exist, caching will be disabled.\n\n----\n\n\u003ca name=\"api\"\u003e\u003c/a\u003e\n## API\n\n\u003ca name=\"compile\"\u003e\u003c/a\u003e\n\n### compile\n\nReturns a callback that binds the data with the template\n\n#### Usage\n\n```\n$handlebars-\u003ecompile(string $string);\n```\n\n#### Parameters\n\n - `string $string` - the template string\n\nReturns `function` - the template binding handler\n\n#### Example\n\n```\n$handlebars-\u003ecompile();\n```\n\n----\n\n\u003ca name=\"getCache\"\u003e\u003c/a\u003e\n\n### getCache\n\nReturns the active cache path\n\n#### Usage\n\n```\n$handlebars-\u003egetCache();\n```\n\nReturns `Closure`\n\n----\n\n\u003ca name=\"getHelper\"\u003e\u003c/a\u003e\n\n### getHelper\n\nReturns a helper given the name\n\n#### Usage\n\n```\n$handlebars-\u003egetHelper('if');\n```\n\n#### Parameters\n\n- `string $name` - the name of the helper\n\nReturns `Closure`\n\n----\n\n\u003ca name=\"getHelpers\"\u003e\u003c/a\u003e\n\n### getHelpers\n\nReturns all the registered helpers\n\n#### Usage\n\n```\n$handlebars-\u003egetHelpers();\n```\n\n#### Parameters\n\nReturns `array`\n\n----\n\n\u003ca name=\"getPartial\"\u003e\u003c/a\u003e\n\n### getPartial\n\nReturns a partial given the name\n\n#### Usage\n\n```\n$handlebars-\u003egetPartial('foobar');\n```\n\n#### Parameters\n\n- `string $name` - the name of the partial\n\nReturns `string`\n\n----\n\n\u003ca name=\"getPartials\"\u003e\u003c/a\u003e\n\n### getPartials\n\nReturns all the registered partials\n\n#### Usage\n\n```\n$handlebars-\u003egetPartials();\n```\n\n#### Parameters\n\nReturns `array`\n\n----\n\n\u003ca name=\"registerHelper\"\u003e\u003c/a\u003e\n\n### registerHelper\n\nThe famous register helper matching the Handlebars API\n\n#### Usage\n\n```\n$handlebars-\u003eregisterHelper(string $name, function $helper);\n```\n\n#### Parameters\n\n - `string $name` - the name of the helper\n - `function $helper` - the helper handler\n\nReturns `Eden\\Handlebrs\\Index`\n\n#### Example\n\n```\n$handlebars-\u003eregisterHelper();\n```\n\n----\n\n\u003ca name=\"registerPartial\"\u003e\u003c/a\u003e\n\n### registerPartial\n\nDelays registering partials to the engine because there is no add partial method...\n\n#### Usage\n\n```\n$handlebars-\u003eregisterPartial(string $name, string $partial);\n```\n\n#### Parameters\n\n - `string $name` - the name of the helper\n - `string $partial` - the helper handler\n\nReturns `Eden\\Handlebrs\\Index`\n\n#### Example\n\n```\n$handlebars-\u003eregisterPartial();\n```\n\n----\n\n\u003ca name=\"setCache\"\u003e\u003c/a\u003e\n\n### setCache\n\nEnables the cache option\n\n#### Usage\n\n```\n$handlebars-\u003esetCache(string $path);\n```\n\n#### Parameters\n\n - `string $path` - The cache path\n\nReturns `Eden\\Handlebrs\\Index`\n\n#### Example\n\n```\n$handlebars-\u003esetCache('/path/to/cache/folder');\n```\n\n---- \n\n\u003ca name=\"setPrefix\"\u003e\u003c/a\u003e\n\n### setPrefix\n\nSets the file name prefix for caching\n\n#### Usage\n\n```\n$handlebars-\u003esetPrefix(string $prefix);\n```\n\n#### Parameters\n\n - `string $prefix` - Custom prefix name\n\nReturns `Eden\\Handlebrs\\Index`\n\n#### Example\n\n```\n$handlebars-\u003esetPrefix('special-template-');\n```\n\n----\n\n\u003ca name=\"unregisterHelper\"\u003e\u003c/a\u003e\n\n### unregisterHelper\n\nThe opposite of registerHelper\n\n#### Usage\n\n```\n$handlebars-\u003eunregisterHelper(string $name);\n```\n\n#### Parameters\n\n - `string $name` - the helper name\n\nReturns `Eden\\Handlebars\\Index`\n\n#### Example\n\n```\n$handlebars-\u003eunregisterHelper();\n```\n\n----\n\n\u003ca name=\"unregisterPartial\"\u003e\u003c/a\u003e\n\n### unregisterPartial\n\nThe opposite of registerPartial\n\n#### Usage\n\n```\n$handlebars-\u003eunregisterPartial(string $name);\n```\n\n#### Parameters\n\n - `string $name` - the partial name\n\nReturns `Eden\\Handlebars\\Index`\n\n#### Example\n\n```\n$handlebars-\u003eunregisterPartial();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcradlephp%2Fhandlebars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcradlephp%2Fhandlebars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcradlephp%2Fhandlebars/lists"}