{"id":15027161,"url":"https://github.com/teodoroleckie/template","last_synced_at":"2026-02-15T09:04:23.936Z","repository":{"id":57070534,"uuid":"360221408","full_name":"teodoroleckie/template","owner":"teodoroleckie","description":"⚡ Fast, powerful, scalable and customizable php template engine","archived":false,"fork":false,"pushed_at":"2021-05-13T09:22:23.000Z","size":51,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T03:34:15.556Z","etag":null,"topics":["easy-template","fast-template","php-8","php-template","php-template-engine","php8","template","template-engine"],"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/teodoroleckie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["teodoroleckie"],"custom":["https://www.paypal.com/donate?business=ZHYA2MTGA4884\u0026currency_code=USD"]}},"created_at":"2021-04-21T15:36:11.000Z","updated_at":"2023-05-20T18:22:19.000Z","dependencies_parsed_at":"2022-08-24T14:54:22.793Z","dependency_job_id":null,"html_url":"https://github.com/teodoroleckie/template","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/teodoroleckie/template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Ftemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Ftemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Ftemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Ftemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teodoroleckie","download_url":"https://codeload.github.com/teodoroleckie/template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teodoroleckie%2Ftemplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29474426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T06:58:05.414Z","status":"ssl_error","status_checked_at":"2026-02-15T06:58:05.085Z","response_time":118,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["easy-template","fast-template","php-8","php-template","php-template-engine","php8","template","template-engine"],"created_at":"2024-09-24T20:05:52.387Z","updated_at":"2026-02-15T09:04:23.914Z","avatar_url":"https://github.com/teodoroleckie.png","language":"PHP","funding_links":["https://github.com/sponsors/teodoroleckie","https://www.paypal.com/donate?business=ZHYA2MTGA4884\u0026currency_code=USD"],"categories":[],"sub_categories":[],"readme":"# Fast and powerful php template engine\nSyntax close to php for easy learning and management.\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/teodoroleckie/template/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/template/?branch=main)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/teodoroleckie/template/badges/code-intelligence.svg?b=main)](https://scrutinizer-ci.com/code-intelligence)\n[![Build Status](https://scrutinizer-ci.com/g/teodoroleckie/template/badges/build.png?b=main)](https://scrutinizer-ci.com/g/teodoroleckie/template/build-status/main)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require tleckie/template\n```\n\n### Printing variable:\n```php\n{{$name}}\n```\nFlexibility of spaces in variables:\n```php\n\u003cp\u003e{{$name}}\u003c/p\u003e\n\n\u003cp\u003e{{   $user-\u003egetName()   }}\u003c/p\u003e\n\n\u003cp\u003e\n    {{\n    $user-\u003egetName()\n    }}\n\u003c/p\u003e\n```\n\n### Printing constant:\n```php\n{{CONSTANT}}\n```\n\n### Set variables:\n```php\n{set $variable = 'test'}\n\n{set $variable = 355}\n\n{set $userId = 25}\n\n{set $userModel = new \\MyNamespace\\User($userId)}\n\n{set $userModel = new \\MyNamespace\\User(25, 'John')}\n```\n### Dump:\n```php\n{dump $users}\n```\n### Comments:\n```txt\n{# {dump $users} #}\n```\n\n\n### Extends template:\n```txt\n\u003chtml\u003e\n\u003chead\u003e\u003c/head\u003e\n\u003cbody\u003e\n\n    {extends Common/Header.html}\n    \n    \u003cp\u003eList\u003c/p\u003e\n        \n    {foreach $users as $user}\n        \u003cp\u003e{{$user-\u003egetName()}}\u003c/p\u003e\n    {endforeach}\n\n    {extends Common/Footer.html}\n\n\u003c/body\u003e\n\u003c/html\u003e\n```\nIf you add changes to the included templates as extensions, the compiler will not show these changes.\nTo remove the compiled files you have the \"flushCompiled()\" method\n\n```php\n$tpl = new Template(__DIR__.'/tpl/', '/var/www/cache/compiled/');\n$tpl-\u003eflushCompiled();\n```\n\nYou can enable development mode so that templates are always compiled.\n```php\nuse Tleckie\\Template\\Template;\n\n$tpl = new Template(\n    __DIR__.'/tpl/', \n    '/var/www/cache/compiled/', \n    null, \n    true // development mode\n);\n```\n\n### Conditionals if, else \u0026 elseif:\n```txt\n{if $title === 'title'}\n    \u003cdiv\u003e{{$title}}\u003c/div\u003e\n{else}\n    It is not a headline!\n{endif}\n```\n```txt\n{if $type === 'Orange'}\n    \u003cdiv\u003e{{$type}}\u003c/div\u003e\n{elseif $title !== 'Apple'}\n    It is not an Apple!\n{else}\n    Other fruit!\n{endif}\n```\n\n```txt\n{if $age \u003e= 18}\n    \u003cdiv\u003eYes!\u003c/div\u003e\n{else}\n    Ups :)\n{endif}\n```\n```txt\n{if $age !== 18}\n    \u003cdiv\u003eYes!\u003c/div\u003e\n{else}\n    Ups :)\n{endif}\n```\n\n### Nested loops:\nForeach and for supported.\n```txt\n\u003chtml\u003e\n\u003chead\u003e\u003c/head\u003e\n\u003cbody\u003e\n\n    {foreach $data as $key =\u003e $persons}\n        {foreach $persons as $id =\u003e $name}\n            \u003cdiv\u003e\u003cstring\u003e{{$name}}:\u003c/string\u003e{{ $key }}\u003c/div\u003e\n        {endforeach}\n    {endforeach}\n    \n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Helpers:\nCreate your own helpers to invoke on the template.\n```php\n{{$this-\u003earrayHelper::last($persons)}}\n```\n\n### Create the template instance:\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Tleckie\\Template\\Template;\n\n$tpl = new Template(__DIR__ . '/tpl/', '/var/www/cache/compiled/');\n\n$data = [\n    'names' =\u003e ['Marcos', 'John', 'Pedro', 'Marta'],\n    'title' =\u003e 'User list',\n    'users' =\u003e [\n        new User('Marcos'), new User('John'), new User('Pedro')\n    ]\n];\n\n$tpl-\u003erender('List/Users.html', $data);\n```\n\nTemplate List/Users.html\n```txt\n\u003chtml\u003e\n\u003chead\u003e\u003c/head\u003e\n\u003cbody\u003e\n    {foreach $users as $user}\n        \u003cp\u003e{{ strtoupper($user-\u003egetName()) }}\u003c/p\u003e\n    {endforeach}\n\u003c/body\u003e\n\u003c/html\u003e\n```\n### Rules:\nThe Tleckie\\Template\\Compiler\\Parser\\Rules class establishes the rules for handling templates.\nYou can create new rules to enrich your templating engine through the RuleInterface interface.\n\n```php\nuse Tleckie\\Template\\Template;\nuse Tleckie\\Template\\Compiler\\Compiler;\nuse Tleckie\\Template\\Compiler\\Parser\\Rules;\n\n$rules = [\n    new Rules(),\n    new MyOwnRules()\n];\n\n$compiler = new Compiler($rules);\n\n$tpl = new Template(\n    __DIR__.'/tpl/', \n    '/var/www/cache/compiled/',\n     $compiler\n);\n```\n\n### Helpers:\nYou can create your own helpers to be invoked from templates to do complex tasks, manipulate objects or strings.\n\nThe Template class has a method for adding helpers. Note that by this mechanism you can also add your dependency injector.\n\n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Tleckie\\Template\\Template;\n\n$tpl = new Template(\n    __DIR__ . '/tpl/', \n    '/var/www/cache/compiled/'\n);\n\n$tpl-\u003eregisterHelper(\n    'arrayHelper', \n    new \\MyNamespace\\Infrastructure\\Helpers\\ArrayHelper()\n);\n```\n\nEach helper added to the template object must have an alias to be invoked through it.\n\n```php\n{{$this-\u003earrayHelper::last($persons)}}\n```\n\nHelper example:\n\n```php\n\u003c?php\n\nnamespace MyNamespace\\Infrastructure\\Helpers;\n\nuse function end;\n\n/**\n * Class ArrayHelper\n * @package MyNamespace\\Infrastructure\\Helpers\n * @author Teodoro Leckie Westberg \u003cteodoroleckie@gmail.com\u003e\n */\nclass ArrayHelper\n{\n    public static function last(array $array)\n    {\n        return end($array);\n    }\n}\n```\n\nThat's all! I hope this helps you ;)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteodoroleckie%2Ftemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteodoroleckie%2Ftemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteodoroleckie%2Ftemplate/lists"}