{"id":22719101,"url":"https://github.com/carry0987/php-template-engine","last_synced_at":"2025-08-07T22:32:07.168Z","repository":{"id":44692927,"uuid":"134661492","full_name":"carry0987/PHP-Template-Engine","owner":"carry0987","description":"Small \u0026 fast php template engine","archived":false,"fork":false,"pushed_at":"2023-10-22T10:46:26.000Z","size":317,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-10-22T11:40:08.023Z","etag":null,"topics":["html","mysqli","php","php-template-engine","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/carry0987.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-05-24T04:37:16.000Z","updated_at":"2023-10-06T11:51:48.000Z","dependencies_parsed_at":"2023-10-22T11:37:58.150Z","dependency_job_id":null,"html_url":"https://github.com/carry0987/PHP-Template-Engine","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-Template-Engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-Template-Engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-Template-Engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-Template-Engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carry0987","download_url":"https://codeload.github.com/carry0987/PHP-Template-Engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229073160,"owners_count":18015807,"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":["html","mysqli","php","php-template-engine","template-engine"],"created_at":"2024-12-10T14:11:27.737Z","updated_at":"2024-12-10T14:17:45.234Z","avatar_url":"https://github.com/carry0987.png","language":"PHP","readme":"# Template-Engine\nSmall \u0026amp; fast php template engine\n\n## Note\nThis project have been **archived**, the new one is [Here](Https://github.com/carry0987/TemplateEngine), using `Composer`.\n\n## Requires\nPHP 7.0 or newer\n\n## Features\n- Support pure html as template\n- Support CSS, JS file cache\n- Support CSS model cache\n- Auto minify CSS cache\n- Cache lifetime\n\n## Usage\nNow you can choose saving version of template file to local or database  \n\nSave to local\n```php\n//Template setting\n$options = array(\n    'template_dir' =\u003e 'template',\n    'css_dir' =\u003e 'static/css/', //Set css file's cache\n    'js_dir' =\u003e 'static/js/', //Set js file's cache\n    'static_dir' =\u003e 'static/', //Set static file's directory\n    'auto_update' =\u003e true, //Set 'false' to turn off auto update template\n    'cache_lifetime' =\u003e 0, //Set cache file's lifetime (minute)\n    'cache_db' =\u003e false //Set 'false' to save cache version at local directory\n);\n```\nSave to database\n```php\n//Connect to Database\n$connectdb = new mysqli('localhost', 'root', 'root', 'template');\n\n//Template setting\n$options = array(\n    'template_dir' =\u003e 'template',\n    'css_dir' =\u003e 'static/css/', //Set css file's cache\n    'js_dir' =\u003e 'static/js/', //Set js file's cache\n    'static_dir' =\u003e 'static/', //Set static file's directory\n    'auto_update' =\u003e true, //Set 'false' to turn off auto update template\n    'cache_lifetime' =\u003e 0, //Set cache file's lifetime (minute)\n    'cache_db' =\u003e $connectdb //Give connection variable to save cache version into database\n);\n```\n## Cache CSS \u0026amp; JS File\n#### CSS Cache\n**Cache specific part of CSS**  \nhtml\n```html\n\u003clink href=\"{loadcss common.css index}\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\nYou can use variable as `specific part`\n```html\n\u003c!--{eval $current_page = 'index'}--\u003e\n\u003clink href=\"{loadcss model.css $current_page}\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\n\nCSS\n```css\n/*[index]*/\n.header {\n    display: block;\n}\n\n.link {\n    color: blue;\n}\n/*[/index]*/\n```\nOutput:\nHTML\n```html\n\u003clink href=\"cache/model_index.css?v=Ad0Dwf8\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\n`cache/model_index.css`\n```css\n/* index */\n.header{display:block}.link{color:blue}\n/* END index */\n```\n\nAlso, with **`array`**\n```html\n\u003c!--{eval $current_page = array('index','test')}--\u003e\n\u003clink href=\"{loadcss model.css $current_page}\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\nCSS\n```css\n/*[index]*/\n.header {\n    display: block;\n}\n\n.link {\n    color: blue;\n}\n/*[/index]*/\n\n/*[test]*/\n.header {\n    display: inline-block;\n}\n\n.link {\n    color: red;\n}\n/*[/test]*/\n```\nOutput:\nHTML\n```html\n\u003clink href=\"cache/model_MULTIPLE.css?v=Ad0Dwf8\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\n`cache/model_MULTIPLE.css`\n```css\n/* index */\n.header{display:block}.link{color:blue}\n/* END index */\n/* test */\n.header{display:inline-block}.link{color:red}\n/* END test */\n```\n\n**Directly cache CSS file**  \nhtml\n```html\n\u003clink href=\"{loadcss common.css}\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\nOutput:\n```html\n\u003clink href=\"static/css/common.css?v=Ad0Dwf8\" rel=\"stylesheet\" type=\"text/css\"\u003e\n```\n\n#### JS Cache\nhtml\n```html\n\u003cscript src=\"{loadjs jquery.min.js}\" type=\"text/javascript\"\u003e\u003c/script\u003e\n```\nOutput:\n```html\n\u003cscript src=\"static/js/jquery.min.js?v=B22PE8W\" type=\"text/javascript\"\u003e\u003c/script\u003e\n```\n\n#### Static File\nhtml\n```html\n\u003cimg src=\"{static img/logo.png}\" alt=\"logo\"\u003e\n```\nOutput:\n```html\n\u003cimg src=\"static/img/logo.png\" alt=\"logo\"\u003e\n```\n\n## Functions\n#### **`echo`** function\nhtml\n```html\n\u003cspan\u003e{$value}\u003c/span\u003e\n```\nPHP\n```php\n\u003cspan\u003e\u003c?php echo $value; ?\u003e\u003c/span\u003e\n```\n\n#### **`assign variable`** function\n\u003eNote: don't put any php script into **`block`** tag\n\nhtml\n```html\n\u003c!--{block test}--\u003e\n\u003cspan\u003ehtml content\u003c/span\u003e\n\u003c!--{/block}--\u003e\n```\nPHP\n```php\n\u003c?php\n$test = \u003c\u003c\u003cEOF\n\n\u003cspan\u003ehtml content\u003c/span\u003e\n\nEOF;\n?\u003e\n```\n\n#### **`if`** function\nhtml\n```html\n\u003c!--{if expr1}--\u003e\n    statement1\n\u003c!--{elseif expr2}--\u003e\n    statement2\n\u003c!--{else}--\u003e\n    statement3\n\u003c!--{/if}--\u003e\n```\nPHP\n```php\n\u003c?php if(expr1) { ?\u003e\n    statement1\n\u003c?php } elseif(expr2) { ?\u003e\n    statement2\n\u003c?php } else { ?\u003e\n    statement3\n\u003c?php } ?\u003e\n```\n\n#### **`loop`** function (without key)\nhtml\n```html\n\u003c!--{loop $array $value}--\u003e\n    \u003cspan\u003eusername\u003c/span\u003e\n\u003c!--{/loop}--\u003e\n```\nPHP\n```php\n\u003c?php foreach($array as $value) {?\u003e\n    \u003cspan\u003eusername\u003c/span\u003e\n\u003c?php } ?\u003e\n```\n\n#### **`loop`** function (with key)\nhtml\n```html\n\u003c!--{loop $array $key $value}--\u003e\n    \u003cspan\u003e{$key} = {$value}\u003c/span\u003e\n\u003c!--{/loop}--\u003e\n```\nPHP\n```php\n\u003c?php foreach($array as $key =\u003e $value) {?\u003e\n    \u003cspan\u003e\u003c?php echo $key; ?\u003e = \u003c?php echo $value; ?\u003e\u003c/span\u003e\n\u003c?php } ?\u003e\n```\n\n#### **`eval`** function\nhtml\n```html\n\u003c!--{eval $value = 1+2}--\u003e\n\u003cspan\u003e{$value}\u003c/span\u003e\n```\nPHP\n```php\n\u003c?php eval $value = 1+2;?\u003e\n\u003cspan\u003e\u003c?php echo $value; ?\u003e\u003c/span\u003e\n```\n\n## **`PRESERVE`** mark\nhtml\n```html\n\u003c!--{PRESERVE}--\u003e\n\u003cspan\u003ehtml content\u003c/span\u003e\n\u003c!--{/PRESERVE}--\u003e\n/*{PRESERVE}*/\n\u003cscript\u003e\nconst value = 1+2;\ndocument.querySelector('span').innerHTML = `Value: ${value}`;\n\u003c/script\u003e\n/*{/PRESERVE}*/\n```\nPHP\n```php\n\u003cspan\u003ehtml content\u003c/span\u003e\n\u003cscript\u003e\nconst value = 1+2;\ndocument.querySelector('span').innerHTML = `Value: ${value}`;\n\u003c/script\u003e\n```\n\n## Thanks\nTemplate **regex function** \u0026amp; **cache method** with big thanks to **[TXGZ](https://github.com/txgz999)**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarry0987%2Fphp-template-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarry0987%2Fphp-template-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarry0987%2Fphp-template-engine/lists"}