{"id":18550314,"url":"https://github.com/xp-forge/mustache","last_synced_at":"2026-01-08T05:31:33.319Z","repository":{"id":7886195,"uuid":"9262618","full_name":"xp-forge/mustache","owner":"xp-forge","description":"The Mustache Template engine for the XP Framework","archived":false,"fork":false,"pushed_at":"2025-05-04T16:35:01.000Z","size":461,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-12T11:30:02.664Z","etag":null,"topics":["mustache","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-04-06T16:06:02.000Z","updated_at":"2025-05-04T16:35:05.000Z","dependencies_parsed_at":"2023-01-13T14:32:39.200Z","dependency_job_id":"07addd5d-29bc-4213-a4ee-8762c41f59d5","html_url":"https://github.com/xp-forge/mustache","commit_stats":null,"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"purl":"pkg:github/xp-forge/mustache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fmustache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fmustache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fmustache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fmustache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-forge","download_url":"https://codeload.github.com/xp-forge/mustache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Fmustache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272628027,"owners_count":24966827,"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-08-29T02:00:10.610Z","response_time":87,"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":["mustache","php","templates","xp-framework"],"created_at":"2024-11-06T21:04:11.861Z","updated_at":"2026-01-08T05:31:33.277Z","avatar_url":"https://github.com/xp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mustache\n========\n\n[![Build status on GitHub](https://github.com/xp-forge/mustache/workflows/Tests/badge.svg)](https://github.com/xp-forge/mustache/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/mustache/version.svg)](https://packagist.org/packages/xp-forge/mustache)\n\nThe [mustache template language](http://mustache.github.io/) implemented for the XP Framework.\n\n```php\nuse com\\github\\mustache\\MustacheEngine;\n\n$transformed= (new MustacheEngine())-\u003erender(\n  'Hello {{name}}',\n  ['name' =\u003e 'World']\n);\n```\n\nIntroduction\n------------\nRead the excellent [mustache man-page](http://mustache.github.io/mustache.5.html) for a start.\n\nFeatures supported\n------------------\nThis implementation supports all standard features of the [current specification](https://github.com/mustache/spec):\n\n* Interpolation: `{{var}}` (`{{\u0026var}}` and triple mustaches for unescaped) and the dot-notation. By default misses will be replaced by empty strings.\n* Comments: `{{! comment }}`. Comments will appear in the parse tree but of course will be excluded when rendering.\n* Delimiters: `{{=@ @=}}` will change the starting and ending delimiter to the `@` sign. Arbitrary length delimiters are supported.\n* Sections: `{{#section}}` as well as inverted sections: `{{^section}}` are supported.\n* Partials: `{{\u003e partial}}` will load a template called `partial.mustache` from the template loader.\n* Implicit iterators: Written as `{{.}}`, the current loop value will be selected.\n\nThe optional *lambdas* module as well as the parent context extension (`../name`) are also supported.\n\nLambdas\n-------\nIf the value is a closure, it will be invoked and the raw text (no interpolations will have been performed!) will be passed to it:\n\n### Template\n```handlebars\n{{# wrapped }}\n  {{ name }} is awesome.\n{{/ wrapped }}\n```\n\n### Data\n```php\n[\n  'name'    =\u003e 'Willy',\n  'wrapped' =\u003e function($text) {\n    return '\u003cb\u003e'.$text.'\u003c/b\u003e';\n  }\n];\n```\n\n### Output\n```html\n\u003cb\u003eWilly is awesome.\u003c/b\u003e\n```\n\n### Extended usage\nThe `$text` parameter passed is actually a `com.github.mustache.Node` instance but may be treated as text as it overloads the string cast. In order to work with it, the node's `evaluate()` method can be called with the `com.github.mustache.Context` instance given as the second argument:\n\n```php\n[\n  'name'    =\u003e 'Willy',\n  'wrapped' =\u003e function($node, $context) {\n    return '\u003cb\u003e'.strtoupper($node-\u003eevaluate($context)).'\u003c/b\u003e';\n  }\n]\n```\n\nTemplate loading\n----------------\nPer default, templates are loaded from the current working directory. This can be changed by passing a template loader instance to the engine:\n\n```php\nuse com\\github\\mustache\\{MustacheEngine, FilesIn};\nuse io\\Folder;\n\n$engine= new MustacheEngine();\n$engine-\u003ewithTemplates(new FilesIn(new Folder('templates')));\n$transformed= $engine-\u003etransform('hello', ['name' =\u003e 'World']);\n```\n\nThis will load the template stored in the file `templates/hello.mustache`. This template loader will also be used for partials.\n\nTemplates can also be loaded from the class loader, use the `com.github.mustache.ResourcesIn` and pass it a class loader instance (e.g. `ClassLoader::getDefault()` to search in all class paths) for this purpose.\n\nCompiled templates\n------------------\nIf you wish to apply variables to a template more than once, you can speed that process up by precompiling templates and using them later on:\n\n```php\nuse com\\github\\mustache\\MustacheEngine;\n\n$engine= new MustacheEngine();\n$template= $engine-\u003ecompile($template);\n\n// Later on:\n$result1= $engine-\u003eevaluate($template, $variables1);\n$result2= $engine-\u003eevaluate($template, $variables2);\n```\n\nHelpers\n-------\nThink of helpers as \"omnipresent\" context. They are added to the engine instance via `withHelper()` and will be available in any rendering context invoked on that instance.\n\n### Template\n```handlebars\n{{# bold }}\n  This is {{ location }}!\n{{/ bold }}\n```\n\n### Call\n```php\nuse com\\github\\mustache\\MustacheEngine;\n\n$engine= new MustacheEngine();\n$engine-\u003ewithHelper('bold', function($text) {\n  return '\u003cb\u003e'.$text.'\u003c/b\u003e';\n});\n$transformed= $engine-\u003erender($template, ['location' =\u003e 'Spartaaaaa']);\n```\n\n### Output\n```html\n\u003cb\u003eThis is Spartaaaaa!\u003c/b\u003e\n```\n\n### Using objects\nYou can also use instance methods as helpers, e.g.\n\n```php\n// Declaration\nclass LocalizationHelpers {\n  public function date($list, $context) {\n    return $context-\u003elookup($list-\u003enodeAt(0)-\u003ename())-\u003etoString('d.m.Y');\n  }\n\n  public function money($list, $context) {\n    // ...\n  }\n}\n\n// Usage with engine instance\n$engine-\u003ewithHelper('local', new LocalizationHelpers());\n```\n\n```handlebars\n{{#local.date}}{{date}}{{/local.date}}\n```\n\nSpec compliance\n---------------\nWhether this implementation is compliant with the official spec can be tested as follows:\n\n```sh\n$ curl -sSL https://github.com/mustache/spec/archive/master.zip -o master.zip\n$ unzip master.zip \u0026\u0026 rm master.zip\n$ xp test com.github.mustache.** -a spec-master/specs/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Fmustache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-forge%2Fmustache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Fmustache/lists"}