{"id":18550298,"url":"https://github.com/xp-forge/handlebars","last_synced_at":"2025-05-15T10:09:06.180Z","repository":{"id":51358841,"uuid":"15525811","full_name":"xp-forge/handlebars","owner":"xp-forge","description":"Handlebars for XP Framework","archived":false,"fork":false,"pushed_at":"2025-05-04T16:34:49.000Z","size":335,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-04T17:02:40.732Z","etag":null,"topics":["handlebars","php","templates","xp-framework"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-forge.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"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}},"created_at":"2013-12-30T10:42:58.000Z","updated_at":"2025-05-04T16:34:53.000Z","dependencies_parsed_at":"2024-11-06T21:04:15.456Z","dependency_job_id":"baca4ce2-5c73-4cc4-8e3d-860f0d46a57e","html_url":"https://github.com/xp-forge/handlebars","commit_stats":null,"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fhandlebars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fhandlebars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fhandlebars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fhandlebars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-forge","download_url":"https://codeload.github.com/xp-forge/handlebars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319722,"owners_count":22051075,"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","php","templates","xp-framework"],"created_at":"2024-11-06T21:04:08.616Z","updated_at":"2025-05-15T10:09:06.150Z","avatar_url":"https://github.com/xp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Handlebars for XP Framework\n============================\n\n[![Build status on GitHub](https://github.com/xp-forge/handlebars/workflows/Tests/badge.svg)](https://github.com/xp-forge/handlebars/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-forge/handlebars/version.svg)](https://packagist.org/packages/xp-forge/handlebars)\n\nThe [Handlebars template language](http://handlebarsjs.com/) implemented for the XP Framework.\n\n```php\nuse com\\handlebarsjs\\HandlebarsEngine;\n\n$engine= new HandlebarsEngine();\n$transformed= $engine-\u003erender('Hello {{name}}', [\n  'name' =\u003e 'World'\n]);\n```\n\nTemplating\n----------\nTemplates can be loaded from the file system. The following loads and transforms the template *src/main/handlebars.handlebars*:\n\n```php\nuse com\\handlebarsjs\\HandlebarsEngine;\n\n$engine= (new HandlebarsEngine())-\u003ewithTemplates('src/main/handlebars');\n$transformed= $engine-\u003etransform('hello', [\n  'name' =\u003e 'World'\n]);\n```\n\nTemplates can also be declared inline:\n\n```php\nuse com\\handlebarsjs\\HandlebarsEngine;\n\n$engine= (new HandlebarsEngine())-\u003ewithTemplates(['test' =\u003e 'Hello {{name}}']);\n$transformed= $engine-\u003etransform('hello', [\n  'name' =\u003e 'World'\n]);\n```\n\nIf you need more flexibility, you can implement and then pass instances of the following:\n\n* `new com.github.mustache.InMemory([:string] $templates))`\n* `new com.github.mustache.FilesIn(string|io.Folder $arg, string[] $extensions)`\n* `new com.github.mustache.ResourcesIn(string|lang.IClassLoader $arg, string[] $extensions)`\n* (Your own implementation of `com.github.mustache.templates.Templates`)\n\nHelpers supported\n-----------------\nThe following helpers are built in:\n\n### The \"if\" block\n```handlebars\n{{#if licence}}\n  A licence is available\n{{/if}}\n\n{{#if licence}}\n  A licence is available\n{{else}}\n  \u003cem\u003eWarning: No licence is available!\u003c/em\u003e\n{{/if}}\n\n{{#if content}}\n  Content\n{{else if hub}}\n  Hub\n{{else}}\n  Default\n{{/if}}\n\n```\n\n### The \"unless\" block\n```handlebars\n{{#unless licence}}\n  \u003cem\u003eWarning: No licence is available!\u003c/em\u003e\n{{/unless}}\n```\n\n### The \"with\" block\n```handlebars\n{{#with person}}\n  Full name: {{firstName}} {{lastName}}\n{{/with}}\n```\n\n### The \"each\" block\n```handlebars\n\u003cul\u003e\n  {{#each students}}\n    \u003cli\u003eStudent's name: {{firstName}} {{lastName}}\u003c/li\u003e\n  {{/each}}\n\u003c/ul\u003e\n```\n\nAll of the above block helpers support the `else` statement.\n\n### The \"log\" helper\n```handlebars\n{{log '\"Hello\", Frank\\'s mother said.'}}\n{{log 'No publishers for' category level=\"warn\"}}\n```\n\nTo enable logging, pass either a closure or a `util.log.LogCategory` instance to the engine:\n\n```php\nuse util\\log\\Logging;\nuse util\\cmd\\Console;\n\n// Use a logger category:\n$logger= Logging::named('trace')-\u003etoConsole();\n\n// Or a closure:\n$logger= function($args, $level) { Console::writeLine('[', $level, '] ', ...$args); };\n\n$engine= (new HandlebarsEngine())-\u003ewithLogger($logger);\n$engine-\u003erender(...);\n```\n\nCustom helpers\n--------------\nTo add custom helpers, use *withHelpers()* and pass functions. The following yields *Hello WORLD*:\n\n```php\nuse com\\handlebarsjs\\HandlebarsEngine;\n\n$engine= (new HandlebarsEngine())-\u003ewithHelper('upper', function($node, $context, $options) {\n  return strtoupper($options[0]);\n});\n$transformed= $engine-\u003erender('Hello {{upper name}}', [\n  'name' =\u003e 'World'\n]);\n```\n\nThe parameters passed are the following:\n\n* **node:** The current node, a `com.github.mustache.Node` instance\n* **context:** The current context, a `com.github.mustache.Context` instance\n* **options:** The resolved options passed, in the above case the string \"World\" (which is what *name* resolves to)\n\nFuther reading\n--------------\nhttps://handlebars-lang.github.io/spec/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Fhandlebars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-forge%2Fhandlebars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Fhandlebars/lists"}