{"id":27206518,"url":"https://github.com/phpffcms/ffcms-templex","last_synced_at":"2025-07-02T15:36:31.727Z","repository":{"id":41530733,"uuid":"119255981","full_name":"phpffcms/ffcms-templex","owner":"phpffcms","description":"Simple native php template system","archived":false,"fork":false,"pushed_at":"2022-08-19T12:50:18.000Z","size":142,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T23:44:05.841Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpffcms.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}},"created_at":"2018-01-28T12:25:10.000Z","updated_at":"2022-06-26T18:30:05.000Z","dependencies_parsed_at":"2022-09-21T12:12:00.675Z","dependency_job_id":null,"html_url":"https://github.com/phpffcms/ffcms-templex","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/phpffcms/ffcms-templex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpffcms%2Fffcms-templex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpffcms%2Fffcms-templex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpffcms%2Fffcms-templex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpffcms%2Fffcms-templex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpffcms","download_url":"https://codeload.github.com/phpffcms/ffcms-templex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpffcms%2Fffcms-templex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263166830,"owners_count":23424253,"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":"2025-04-09T23:43:38.334Z","updated_at":"2025-07-02T15:36:31.626Z","avatar_url":"https://github.com/phpffcms.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Templex\nTemplex - native php template system build on top of php plates framework: [thephpleague/plates](https://github.com/thephpleague/plates). Templex used in phpffcms as a basic template engine with pack of html helpers that makes posible fast build html-code output.\n\n## Installation\nUsing composer: \n```bash\ncomposer require phpffcms/ffcms-templex\n```\n## Usage\nTo see complete examples please take a look on ```/example``` directory. \n\n### Initialize\nHere you can see a simple example of template system initialization:\n```php\n$loader = require __DIR__ . '/vendor/autoload.php';\n\n// initialize template engine\n$tpl = new \\Ffcms\\Templex\\Engine(__DIR__ . '/tpl');\n// load default ffcms html helpers as extensions\n$tpl-\u003eloadDefaultExtensions();\n\n// render /tpl/block.body.php example\necho $tpl-\u003erender('block/body', ['test' =\u003e 'some value']);\n```\n\n### Use layouts\nThe major feature of any template system is a layouts. Plates provide a complete feature to use layouts in templating:\n```php\n$this-\u003elayout('path/to/file', ['var' =\u003e 'value']);\n```\n\n### Sections extend\nSection allow you to make dynamic templates with block override features. To understand how section extending works take a look at simple example:\n\n```/tpl/block/body.php```\n```php\n\u003c?php\n$this-\u003elayout('layout', ['title' =\u003e 'My first title']);\n?\u003e\n\n\u003c?php $this-\u003estart('body') ?\u003e\n\u003ch1\u003eHello, world!\u003c/h1\u003e\n\u003cp\u003eThis is my first template\u003c/p\u003e\n\u003c?php $this-\u003estop(); ?\u003e\n```\nand ```/tpl/layout.php```:\n```php\n\u003cdoctype html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003e\u003c?= $title ?\u003e\u003c/title\u003e\n\u003cbody\u003e\n\u003c?= $this-\u003esection('body'); ?\u003e\n\u003c/body\u003e\n\u003c/head\u003e\n\u003c/html\u003e\n```\nAfter initialization and executing ```$tpl-\u003erender('block/body')``` the output will be:\n```html\n\u003cdoctype html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003eMy first title\u003c/title\u003e\n\u003cbody\u003e\n\u003ch1\u003eHello, world!\u003c/h1\u003e\n\u003cp\u003eThis is my first template\u003c/p\u003e\n\u003c/body\u003e\n\u003c/head\u003e\n\u003c/html\u003e\n```\nThe ```body``` section in ```layout.php``` after rendering accept the result from ```start('body')``` ... ```stop()``` section. You can make a multiple extend by section using ```-\u003epush('name')``` instead of ```-\u003estart('name')```.\n\n### Html helpers\nTemplex provide simple and clear php-based html code generator. The main part of developing process in any application is to build html output of tables, listing, grids and forms.\n\nIn this section you will see the main features of html code generator helpers. \n\n#### Listing\nTo draw a simple listing you should use ```$this-\u003elisting('type', [properties])``` and then call ```li([items], [properties])``` to add each one ```\u003cli\u003e\u003c/li\u003e``` element. \n\nListing can be used inline or as named factory object. Inline object usage are prefered for pre-defined elements that should be displayed \"right here\":\n```php\necho $this-\u003elisting('ul')\n    -\u003eli('item 1')\n    ...\n    -\u003eli('item n')\n    -\u003edisplay()\n```\nNamed object can be defined for more complex usage. For example - add elements of listing in cycle:\n```php\n$listing = $this-\u003elisting('ul');\n\nfor ($i = 0; $i \u003c 100; $i++) {\n    $listing-\u003eli('Item #' . $i);\n}\n\necho $listing-\u003edisplay();\n```\n\nComplete example with some \"magic\":\n```php\necho $this-\u003elisting('ul', ['class' =\u003e 'my-listing'])\n    -\u003eli('Text item')\n    -\u003eli(['text' =\u003e 'Google link', 'link' =\u003e ['https://google.com']])\n    -\u003eli(['text' =\u003e 'Local link', 'link' =\u003e ['controller/action', ['id' =\u003e 1]], 'properties' =\u003e ['class' =\u003e 'li-item']])\n    -\u003edisplay();\n````\nwill compile to output:\n```html\n\u003cul class=\"my-listing\"\u003e\n  \u003cli\u003eText item\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"https://google.com\"\u003eGoogle link\u003c/a\u003e\u003c/li\u003e\n  \u003cli class=\"li-item\"\u003e\u003ca href=\"http://localhost/controller/action/1\"\u003eLocal link\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n#### Table\nTables often used to display structured data. Templex provide helper to draw table simple \u0026 fast. To draw table you should use ``$this-\u003etable([properties])`` instance and then implement thead ``-\u003ehead([properties], [items])`` features and tbody ``-\u003erow([items], order)`` items and finally call ``-\u003edisplay()`` to get html output.\n\nAs a listings, table can be used in inline or names style (careful! code below is symbolic):\n```\n// inline call:\necho $this-\u003etable([properties])\n    -\u003ehead([properties], [titles])\n    -\u003erow([items1])\n    -\u003erow([items2])\n    -\u003edisplay();\n    \n // named call:\n$table = $this-\u003etable([properties]);\n$table-\u003ehead([properties], [titles])\nfor ($i = 0; $i \u003c 100; $i++) {\n    $table-\u003erow([elements]);\n}\necho $table-\u003edisplay();\n```\n\nSo take a look at complete example:\n```php\necho $this-\u003etable(['class' =\u003e 'table'])\n    -\u003ehead(['class' =\u003e 'table-header'], [\n        ['text' =\u003e 'column1'],\n        ['text' =\u003e 'column2'],\n        ['text' =\u003e 'column3'],\n    ])\n    -\u003erow([\n        ['text' =\u003e 'row 1, \u003cstrong\u003ecolumn1\u003c/strong\u003e', 'html' =\u003e true], // html allowed\n        ['text' =\u003e 'row 1, column2', 'properties' =\u003e ['class' =\u003e 'alert alert-danger']],\n        ['text' =\u003e 'row 1, column3']\n    ])\n    -\u003erow([\n        ['text' =\u003e 'row 2, column1'],\n        ['text' =\u003e 'row 2, \u003cem\u003ecolumn2\u003c/em\u003e'], // html not allowed!\n        ['text' =\u003e 'row 2, column3'],\n        'properties' =\u003e ['class' =\u003e 'alert alert-success']\n    ])\n    -\u003edisplay();\n```\nlead to output:\n```html\n\u003ctable class=\"table\"\u003e\n    \u003cthead class=\"table-header\"\u003e\n    \u003ctr\u003e\u003cth\u003ecolumn1\u003c/th\u003e\n        \u003cth\u003ecolumn2\u003c/th\u003e\n        \u003cth\u003ecolumn3\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n        \u003ctr\u003e\n            \u003ctd\u003erow 1, \u003cstrong\u003ecolumn1\u003c/strong\u003e\u003c/td\u003e\n            \u003ctd class=\"alert alert-danger\"\u003erow 1, column2\u003c/td\u003e\n            \u003ctd\u003erow 1, column3\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr class=\"alert alert-success\"\u003e\n            \u003ctd\u003erow 2, column1\u003c/td\u003e\n            \u003ctd\u003erow 2, \u0026lt;em\u0026gt;column2\u0026lt;/em\u0026gt;\u003c/td\u003e\n            \u003ctd\u003erow 2, column3\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e   \n```\nIf you want to use html syntax in ``text`` property you should pass ```'html' = true``` in item array.\n##### Selectize column\nTable helper provide feature to display multiple checkboxes at table column index. If you want to add at each element of column checkbox input field, use selectize:\n```php\n$this-\u003etable([properties])\n    -\u003eselectize(index, name)\n```\nNote, that ```-\u003eselectize()``` should be used before ```-\u003ehead()``` or ```-\u003erow()``` called. \n\n\n\n##### Sortable column\nIf you want to sort data in tables you can use sorter helper of table building. Sorter add up/down arrow at defined column index with named link. \n```php\n$this-\u003etable([properties])\n    -\u003esortable([\n        0 =\u003e 'getname' // will build ?getname=1 and ?getname=2 links as asc/desc sorting query\n    ])\n```\n\n#### Forms\nForm helper provide features of fast form field building, styling and display. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpffcms%2Fffcms-templex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpffcms%2Fffcms-templex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpffcms%2Fffcms-templex/lists"}