{"id":15029825,"url":"https://github.com/phpmohamednabil/style","last_synced_at":"2026-02-11T16:35:41.251Z","repository":{"id":174504192,"uuid":"93356058","full_name":"PHPMohamedNabil/Style","owner":"PHPMohamedNabil","description":"PHP Template Engine","archived":false,"fork":false,"pushed_at":"2023-07-28T06:32:27.000Z","size":191,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T02:42:14.904Z","etag":null,"topics":["framwork-design-web","html5","php","php-framework","php-library","php7","php74","php8","php8-features","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/PHPMohamedNabil.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-05T02:15:27.000Z","updated_at":"2023-06-13T05:28:46.000Z","dependencies_parsed_at":"2024-12-18T07:45:31.858Z","dependency_job_id":"329b3b31-0372-4976-acce-ccdbb7041ee9","html_url":"https://github.com/PHPMohamedNabil/Style","commit_stats":null,"previous_names":["phpmohamednabil/styleengine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPMohamedNabil%2FStyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPMohamedNabil%2FStyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPMohamedNabil%2FStyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHPMohamedNabil%2FStyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PHPMohamedNabil","download_url":"https://codeload.github.com/PHPMohamedNabil/Style/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280177,"owners_count":20912965,"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":["framwork-design-web","html5","php","php-framework","php-library","php7","php74","php8","php8-features","template-engine"],"created_at":"2024-09-24T20:11:43.018Z","updated_at":"2026-02-11T16:35:41.225Z","avatar_url":"https://github.com/PHPMohamedNabil.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Style\n\nBy Mohamed Nabil (https://github.com/PHPMohamedNabil/)!\n\n[Style]\nis lightweight a tiny PHP Template Engine you can use for small projects or educational purposes.\n\nFeel the power of the template engines of big libraries in your code with simple and flexible usage and little code.\n\nFeatures\n--------\n* Simple compiling tags *{$variable}*, *{#constant}*, @include(), *{%loop $data%}*, *{%if%}*, *[* comment *]*,, *{%func echo str_len($string)%}*\n* Very Easy template Compiling as one class called Style just loads the full template and compiling it.\n* [new feature] (Hardcompiling Templates) to send data to other template file so that be injected into other template in every page load.\n* Easy to inject a new experissions fell free to add as many as you want.\n* Secure when printing variables , as its filtered html content against some  xss attacks.\n\nTable of contents\n=================\n\n\u003c!--ts--\u003e\n   * [Installation](#installation)\n   * [Usage](#usage)\n      * [Custom Expressions](#custom-expressions)\n      * [Sections](#sections)\n      * [Hard Compiling](#hard-compiling-feature)\n      * [Including View](#including-view)\n      * [Foreach loop](#foreach-loop)\n      * [Html Creation](#html-creation)\n      * [Printing Vars](#printing-vars)\n      * [Terminate the code](#terminate-the-code)\n      * [Printing html Content](#printing-html-content)\n      * [Table of expressions](#Expressions-of-statments)\n   * [Licence](#licence)\n\u003c!--te--\u003e\n\n\nInstallation\n------------\n\n1. Install composer https://github.com/composer/composer\n2. Create a composer.json inside your application folder:\n\n    ``` composer require php-mohamed-nabil/style ```\n    \nUsage\n-----\nCreate a Style instance by passing it the folder where your view files are located, and a cache folder. Render a template by calling the render method.\n\n```php\nuse Style\\Style;\n\n$style = new Style('template/','template/temp/');\n\n$style-\u003erender('page_sections',[]);\n```\n## Custom-Expressions \nYou can also add custom expressions using the `addTempRole()` function:\n\n```php\n$style-\u003eaddTempRole('test','\\~ob',function($capt){\n\t  return $capt[0].'  ppppppppppppppppppoboobobo';\n});\n$style-\u003erender('page_sections',[]);\n```\nWhich allows you to use the following in your  template:\n\n```\n here the ppppppppp : ~ob\n```\n## Sections\nYou can also use extend views and using @spread(parent_view_name)\n\n```html\n@spread('layout')\n```\nusing also @sections @addsection to send data from child to parent view\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003cmeta charset=\"utf-8\"\u003e\n\t\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n\t\u003ctitle\u003elayout page\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\n\u003cp class=\"yield\"\u003e\n    \u003c!-- this will yield data and print it here form child view --\u003e\n\t@addsection('content')\n\u003c/p\u003e\n\n\u003c/html\u003e\n```\n```html\n@spread('layout')\n\n\u003c!-- add data to the main view and render show it --\u003e\n@section('content')\n  My first paragraph in parent view \n@endsection\n```\n\n## Hard-compiling-Feature\n\nyou can now send data from one view to another one as it will be compiled and hardcoded example :\n### in the view main you will write the below expression that when view main.stl.php page loaded or compilled\n### The view test will be injected by random number in every main.stl.php page load within h1 tag that has class title\n```html\n\n@hardcompile(test[] within h1:title data:\"echo mt_rand(1,1000)\")\n```\nresults in test.stl.php\n```html\n\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003cmeta charset=\"utf-8\"\u003e\n\t\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n\t\u003ctitle\u003eTest\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\n\u003ch1 class=\"title\"\u003e\n681 \u003c!-- this a random number hardcoded by main view  --\u003e\n\u003c/h1\u003e\n    \n```\n### hard compilling can be (before | after | within) the specified tag in other view to be injected\nyou can send data to other view like this :\n```html\n\n@hardcompile(test['name'=\u003e$name,$title] before h1:title data:\"echo mt_rand(1,1000)\")\n```\n\n## including-view \nget other view included in view page\n```html\n@display('main',['data'=\u003e$data])\n```\n## foreach-loop \nin tempaltes \n\n```html\n\u003cdiv class=\"\"\u003e\n@foreach($users as $user)\n  {$user-\u003eusername}\n@endforeach\n\u003c/div\u003e\n```\n## Html-Creation \nyou can now create form with its input data \n\n```php\n[php]\n       print \\Style\\Style::form('/',[\n        'method'=\u003e'post',\n        'enctype'=\u003e'multipart/form-data',\n        'id'=\u003e'first-form'\n   ])-\u003eformInput('username',['class'=\u003e'form-control','type'=\u003e'text'])-\u003eformInput('password',['class'=\u003e'form-control','type'=\u003e'password'])-\u003eformInput('file',['class'=\u003e'form-input-file','type'=\u003e'file'])-\u003erenderForm();\n\n  [/php]\n```\nwill output:\n```html\n\u003cform action=\"/\" method=\"post\" enctype=\"multipart/form-data\" id=\"first-form\"\u003e\n\n\t\t\u003cinput name=\"username\" class=\"form-control\" type=\"text\"\u003e\n\n\t\t\u003cinput name=\"password\" class=\"form-control\" type=\"password\"\u003e\n\n\t\t\u003cinput name=\"file\" class=\"form-input-file\" type=\"file\"\u003e\n\n\u003c/form\u003e\n```\n### Printing-Vars\n```html\n{$var_name}\n```\n## Terminate-the-code\nof view like die\nyou can use @backwithfalse it is just converted to return false and exit from code any code or html after it will not be executed\n\n## printing-html-content\nwithout stopping entities\nyou can print html code witout escaping it the main reason of it if you want to show a post content or has a block of html code\nto be appear and effected by browser  you can use {@$post@} as an expample:\n```html\n\u003cdiv class=\"blog-post-content\"\u003e\n{@$posts-\u003epost_content@}\n\u003c/div\u003e\n```\n## Expressions-of-statments:\n| Expression | Description |\n| --- | --- |\n| `{$var}` | for printing the variable var with **escaping against xss** |\n| `{%$var%}` | printing var or any string escaping or filtering it  |\n| `{@$var@}` | printing var or any string **without** escaping it or filtering it  |\n| `{%var='name'}` | define a variable inside the view :**$var='name'**|\n| `{%func echo ucfirst($var)%}` |execute the function or echo it **echo word is optional if you want to echo the function**|\n| `[comment]ww [/comment]` | any thing in between it will not be compilled|\n| `[php] var_dump($arr); [/php]` | write php code|\n| `{%if $var\u003e0%}` | define if statment|\n| `{%else%},{%elseif%} and {%endif%}` | define else or elseif statment and you can use endif statment to end the statment|\n| `@addsection($name)` |used in layout or parent view to implement section content that will be printed later in child view |\n| `@spread($name)` | extend the parent view in the child view |\n| `@section($name)` | start the section in child view |\n| `@endsection($name)` | end the section in child view |\n| `@foeach` | start the for each loop |\n| `@endforeach` | end the for each loop |\n| `@for()` | start the for  loop |\n| `@endfor` | end the for  loop |\n| `@while()` | start while statment |\n| `@endwhile` |  end while statment |\n| `@switch($var)` | start the switch statment |\n| `@case($name)` | case condition inside switch statment |\n| `@break` | break the statment or the loop |\n| `@continue` | continue the statment or the loop |\n| `@default` | default condition inside switch statment |\n| `@backwithfalse` |  it is just converted to return false and exit from code any code or html after it will not be executed |\n| `@hardcompile(view_name[] before\\|after\\|within tagname:classname data:\"php_code_here\")` | hard compiling other **view_name** and inject data content before or after or within tagname that has a classname this will send data to other view on every exacute of this experission |\n\n\n\n\n\n\n Licence\n-------\n\npublished under the MIT Licence.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpmohamednabil%2Fstyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpmohamednabil%2Fstyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpmohamednabil%2Fstyle/lists"}