{"id":34000292,"url":"https://github.com/fire015/spin","last_synced_at":"2026-04-06T09:01:52.352Z","repository":{"id":57056730,"uuid":"40178550","full_name":"fire015/spin","owner":"fire015","description":"An Active Record like pattern for template rendering with PHP - supporting Twig, Smarty, Plates and Dwoo.","archived":false,"fork":false,"pushed_at":"2015-08-07T10:11:35.000Z","size":124,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-13T09:58:50.809Z","etag":null,"topics":[],"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/fire015.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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-08-04T10:31:51.000Z","updated_at":"2022-07-31T16:54:27.000Z","dependencies_parsed_at":"2022-08-24T14:52:57.081Z","dependency_job_id":null,"html_url":"https://github.com/fire015/spin","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/fire015/spin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fire015%2Fspin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fire015%2Fspin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fire015%2Fspin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fire015%2Fspin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fire015","download_url":"https://codeload.github.com/fire015/spin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fire015%2Fspin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31466228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2025-12-13T09:20:19.955Z","updated_at":"2026-04-06T09:01:52.346Z","avatar_url":"https://github.com/fire015.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Spin Template\n==========\n\n[![Total Downloads](https://img.shields.io/packagist/dm/spin/template.svg)](https://packagist.org/packages/spin/template)\n[![Build Status](https://travis-ci.org/fire015/spin.svg?branch=master)](https://travis-ci.org/fire015/spin)\n\nAn Active Record like pattern for template rendering with PHP.\n\n* Define and retrieve variables\n* Accessor and mutator functions\n* Render in any engine\n* Built in support for Twig, Smarty, Plates and Dwoo\n\n## Installation\n\nInstall Spin via [composer](http://getcomposer.org/). Then extend `Spin\\Template\\Template`.\n\n```\ncomposer require spin/template\n```\n\n## Example\n\n```php\nclass Homepage extends Spin\\Template\\Template\n{\n\t/**\n\t * The template file\n\t */\n\tprotected $file = 'templates/home.php';\n\n\t/**\n\t * Convert the first character of first name to uppercase on retrieval\n\t */\n    public function getFirstNameAttribute($value)\n    {\n        return ucfirst($value);\n    }\n\n\t/**\n\t * Convert the whole string to lowercase when setting first name\n\t */\n    public function setFirstNameAttribute($value)\n    {\n        $this-\u003eattributes['first_name'] = strtolower($value);\n    }\n\n\t/**\n\t * Convert the unix timestamp to a human friendly date on retrieval\n\t */\n\tpublic function getDateAttribute($value)\n\t{\n\t\treturn date('Y-m-d', $value);\n\t}\n}\n\n$template = new Homepage();\n\n// Assign variables as properties\n$template-\u003efirst_name = 'john';\n$template-\u003edate = time();\n\n// You can also assign variables as an array\n$template['weather'] = 'frightful';\n\n// Render the template\necho $template-\u003erender();\n```\n\ntemplates/home.php:\n```php\nHello \u003c?php echo $first_name; ?\u003e today's date is \u003c?php echo $date; ?\u003e. The weather outside is \u003c?php echo $weather; ?\u003e\n```\n\nOutput:\n```\nHello John today's date is 2015-08-05. The weather outside is frightful.\n```\n\nAs you can see we assign variables to our class either via properties or array syntax and call the `render()` method, which passes those variables to our template defined in `$file` and return's the rendered template.\n\n#### Accessors and mutators\n\nAccessors and mutators allow you to format template variables when retrieving them for rendering or setting their value.\n\nIf you have ever used [Eloquent mutators](http://laravel.com/docs/5.1/eloquent-mutators) for getting/setting data on an object it's the same concept (in fact it's almost the same code - thanks Laravel).\n\nTo define an accessor, create a `getFooAttribute` method in your class where `Foo` is the camel cased name of the variable you wish to access. See the `getFirstNameAttribute` method in the example above.\n\nTo define a mutator, create a `setFooAttribute` method in your class where `Foo` is the camel cased name of the variable you wish to change. See the `setFirstNameAttribute` method in the example above.\n\n## Rendering engine\n\nTo use a different rendering engine pass an object that implements `Spin\\Template\\Engine\\EngineInterface` to the `setEngine` method.\n\nSupport for Twig, Smarty, Plates and Dwoo are already included and can be implemented as per the examples below:\n\n#### Twig\n```php\nclass Homepage extends Spin\\Template\\Template\n{\n\tprotected $file = 'home.twig';\n\n\tpublic function __construct()\n\t{\n\t\t$loader = new Twig_Loader_Filesystem('/path/to/templates');\n\t\t$twig = new Twig_Environment($loader);\n\n\t\t$this-\u003esetEngine(new Spin\\Template\\Engine\\TwigEngine($twig));\n\t}\n}\n```\n\n#### Smarty\n```php\nclass Homepage extends Spin\\Template\\Template\n{\n\tprotected $file = 'home.smarty';\n\n\tpublic function __construct()\n\t{\n\t\t$smarty = new Smarty();\n\t\t$smarty-\u003esetTemplateDir('/path/to/templates');\n\t\t$smarty-\u003esetCompileDir('/path/to/templates_c');\n\n\t\t$this-\u003esetEngine(new Spin\\Template\\Engine\\SmartyEngine($smarty));\n\t}\n}\n```\n\n#### Plates\n```php\nclass Homepage extends Spin\\Template\\Template\n{\n\tprotected $file = 'home';\n\n\tpublic function __construct()\n\t{\n\t\t$plates = new League\\Plates\\Engine('/path/to/templates');\n\n\t\t$this-\u003esetEngine(new Spin\\Template\\Engine\\PlatesEngine($plates));\n\t}\n}\n```\n\n#### Dwoo\n```php\nclass Homepage extends Spin\\Template\\Template\n{\n\tprotected $file = 'home.dwoo';\n\n\tpublic function __construct()\n\t{\n\t\t$dwoo = new Dwoo\\Core();\n\t\t$dwoo-\u003esetTemplateDir('/path/to/templates');\n\t\t$dwoo-\u003esetCompileDir('/path/to/templates_c');\n\n\t\t$this-\u003esetEngine(new Spin\\Template\\Engine\\DwooEngine($dwoo));\n\t}\n}\n```\n\n## About\n\n### Requirements\n\n- Spin works with PHP 5.4 or above (excluding the requirements for any template engine you use)\n\n### Submitting bugs and feature requests\n\nBugs and feature request are tracked on [GitHub](https://github.com/fire015/spin/issues).\n\n### License\n\nSpin is licensed under the MIT License - see the `LICENSE.md` file for details.\n\n### Acknowledgements\n\nThis library is heavily inspired by Laravel's Eloquent model class. Thanks guys!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffire015%2Fspin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffire015%2Fspin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffire015%2Fspin/lists"}