{"id":20903497,"url":"https://github.com/phly/phly-mustache","last_synced_at":"2025-05-13T04:33:18.061Z","repository":{"id":45137038,"uuid":"41810676","full_name":"phly/phly-mustache","owner":"phly","description":"Extensible Mustache templating for PHP","archived":false,"fork":false,"pushed_at":"2022-01-05T22:07:20.000Z","size":673,"stargazers_count":15,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T04:18:45.188Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-02T15:50:35.000Z","updated_at":"2025-01-29T19:32:28.000Z","dependencies_parsed_at":"2022-08-26T08:50:52.978Z","dependency_job_id":null,"html_url":"https://github.com/phly/phly-mustache","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-mustache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-mustache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-mustache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-mustache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phly","download_url":"https://codeload.github.com/phly/phly-mustache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253877265,"owners_count":21977632,"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":[],"created_at":"2024-11-18T13:13:42.420Z","updated_at":"2025-05-13T04:33:17.037Z","avatar_url":"https://github.com/phly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phly-mustache\n\n[![Build Status](https://secure.travis-ci.org/phly/phly-mustache.png?branch=develop)](http://travis-ci.org/phly/phly-mustache)\n\nphly-mustache is a [Mustache](http://mustache.github.com) implementation written\nfor PHP. It conforms to the principles of mustache, and allows for\nextension of the format via pragmas.\n\nIn particular, it offers support for [template\ninheritance](https://github.com/mustache/spec/pull/75) ala\n[hogan.js](https://github.com/twitter/hogan.js), using the `{{\u003cparent}}` syntax.\n\nFor full documentation, please visit\n[ReadTheDocs](http://phly-mustache.readthedocs.org/).\n\nThe mailing list is at https://groups.google.com/d/forum/phly_mustache\n\n## Installation\n\nInstall via composer:\n\n```bash\n$ composer require phly/phly-mustache\n```\n\n## Documentation\n\nDocumentation builds are available at:\n\n- https://phly-mustache.readthedocs.org\n\nYou can also build documentation in one of two ways:\n\n- [MkDocs](http://www.mkdocs.org): Execute `mkdocs build` from the repository\n  root.\n- [Bookdown](http://bookdown.io): Execute `bookdown doc/bookdown.json` from the\n  repository root.\n\nIn each case, you can use PHP's built-in web server to serve the documentation:\n\n```bash\n$ php -S 0.0.0.0:8080 -t doc/html/\n```\n\nand then browse to http://localhost:8080/.\n\n## Usage\n\nBasic usage is:\n\n```php\nuse Phly\\Mustache\\Mustache;\n\nrequire 'vendor/autoload.php';\n\n$mustache = new Mustache();\necho $mustache-\u003erender('some-template', $view);\n```\n\nBy default, phly-mustache will look under the current directory for templates\nending with '.mustache'; you can create a stack of directories using the\ndefault resolver:\n\n```php\nuse Phly\\Mustache\\Resolver\\DefaultResolver;\n\n$resolver = new DefaultResolver();\n$resolver-\u003eaddTemplatePath($path1);\n$resolver-\u003eaddTemplatePath($path2);\n\n$resolver = $mustache-\u003egetResolver()-\u003eattach($defaultResolver);\n```\n\nIn the above, it will search first `$path2`, then `$path1` to resolve the\ntemplate.\n\nThe default resolver is composed in an aggregate resolver by default; as such,\nyou can also fetch it by type from the aggregate instead of adding it manually:\n\n```php\nuse Phly\\Mustache\\Resolver\\DefaultResolver;\n\n$resolver = $mustache-\u003egetResolver()-\u003efetchByType(DefaultResolver::class);\n```\n\nTemplate names may be namespaced, using the syntax `namespace::template`:\n\n```php\n$resolver-\u003eaddTemplatePath($path1, 'blog');\n$resolver-\u003eaddTemplatePath($path2, 'contact');\n```\n\nPer the above configuratin, rendering the template `contact::index` will resolve\nto `$path2`. If it cannot, it will drop back to the default namespace (any paths\nregistered without a namespace).\n\nYou may also change the suffix it will use to resolve templates:\n\n```php\n$resolver-\u003esetSuffix('html'); // use '.html' as the suffix\n```\n\nIf your templates use pragmas, you must first add pragma handlers to the\n`Mustache` pragma collection. This can be done as follows:\n\n```php\nuse Phly\\Mustache\\Pragma\\ImplicitIterator as ImplicitIteratorPragma;\n\n$mustache-\u003egetPragmas()-\u003eadd(new ImplicitIteratorPragma());\n$mustache-\u003erender('template-with-pragma', $view);\n```\n\nViews can be either associative arrays or objects. For objects, any public\nmember, either a property or a method, may be referenced in your template. As an\nexample:\n\n```php\nclass View\n{\n    public $first_name = 'Matthew';\n\n    public $last_name  = \"Weier O'Phinney\";\n\n    public function full_name()\n    {\n        return $this-\u003efirst_name . ' ' . $this-\u003elast_name;\n    }\n}\n```\n\nAny property (or array key) may also refer to a valid callback; in such cases,\nthe return value of the callback will be used.\n\n```php\n$view = new stdClass;\n$view-\u003efirst_name = 'Matthew';\n$view-\u003elast_name  = \"Weier O'Phinney\";\n$view-\u003efull_name  = function() use ($view) {\n    return $view-\u003efirst_name . ' ' . $view-\u003elast_name;\n};\n```\n\nRefer to the documentation ([online](http://phly-mustache.readthedocs.org) /\n[local](doc/book/)) for full usage details.\n\n## Architecture\n\nPhly\\Mustache consists of five primary classes:\n\n- **Lexer**: tokenizes mustache syntax.\n- **Renderer**: renders a list of tokens, using substitions provided via a view.\n- **Pragma\\PragmaInterface**: interface for pragmas, which may modify how tokens are handled.\n- **Resolver\\ResolverInterface**: resolves a template name to mustache syntax or tokens.\n- **Mustache**: facade/gateway class. Tokenizes and renders templates, caches\n  tokens, provides partial aliasing, aggregates pragmas, and acts as primary\n  interface for end-users.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-mustache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphly%2Fphly-mustache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-mustache/lists"}