{"id":18555644,"url":"https://github.com/n2ref/micro_templater","last_synced_at":"2025-05-15T13:10:21.653Z","repository":{"id":22745382,"uuid":"26090598","full_name":"n2ref/Micro_Templater","owner":"n2ref","description":"Simple and strong templater","archived":false,"fork":false,"pushed_at":"2015-10-17T10:48:55.000Z","size":193,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T11:28:29.888Z","etag":null,"topics":["php","template-engine"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/n2ref.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":"2014-11-02T19:20:28.000Z","updated_at":"2023-04-09T14:41:21.000Z","dependencies_parsed_at":"2022-08-05T19:00:33.852Z","dependency_job_id":null,"html_url":"https://github.com/n2ref/Micro_Templater","commit_stats":null,"previous_names":["n2ref/micro_templater"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n2ref%2FMicro_Templater","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n2ref%2FMicro_Templater/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n2ref%2FMicro_Templater/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n2ref%2FMicro_Templater/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n2ref","download_url":"https://codeload.github.com/n2ref/Micro_Templater/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346626,"owners_count":22055809,"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":["php","template-engine"],"created_at":"2024-11-06T21:27:27.134Z","updated_at":"2025-05-15T13:10:21.632Z","avatar_url":"https://github.com/n2ref.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Micro Templater\n===============\n\nSimple but powerful PHP template engine. \u003cbr\u003e\nJust one file. \u003cbr\u003e\nHave a look how it easy to use. \u003cbr\u003e\n\n#### Examples\n\n##### Variables\n###### Example # 1 Using the method 'assign'\n\n```php\n$html = '\n    Title\n    \u003cul\u003e\n        \u003cli class=\"var1\"\u003e\n            [var2]\n        \u003c/li\u003e\n    \u003c/ul\u003e\n';\n \n$tpl = new Mtpl();\n$tpl-\u003esetTemplate($html);\n \n$tpl-\u003eassign('var1',   'foo');\n$tpl-\u003eassign('[var2]', 'bar');\n \necho $tpl-\u003erender();\n```\nResult will look like:\n\n```html\nTitle\n\u003cul\u003e\n    \u003cli class=\"foo\"\u003e\n        bar\n    \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n##### Blocks\n\n###### Example # 1 A clear indication of the block\n```php\n$html = '\n    Title\n    \u003c!-- BEGIN error --\u003e\n    \u003cdiv class=\"error\"\u003eExemple 1: error message!\u003c/div\u003e\n    \u003c!-- END error --\u003e\n';\n \n$tpl = new Mtpl();\n$tpl-\u003esetTemplate($html);\n \n$tpl-\u003etouchBlock('error');\n \necho $tpl-\u003erender();\n```\nResult will look like:\n\n```html\nTitle\n\u003cdiv class=\"error\"\u003eExemple 1: error message!\u003c/div\u003e\n```\n\n###### Example # 2 Implicit indication block\n```php\n$html = '\n    Title\n    \u003c!-- BEGIN error --\u003e\n    \u003cdiv class=\"error\"\u003e[message]\u003c/div\u003e\n    \u003c!-- END error --\u003e\n';\n \n$tpl = new Mtpl();\n$tpl-\u003esetTemplate($html);\n \n$tpl-\u003eerror-\u003eassign('[message]', 'Exemple 2: error message!');\n \necho $tpl-\u003erender();\n```\nResult will look like:\n\n```html\nTitle\n\u003cdiv class=\"error\"\u003eExemple 2: error message!\u003c/div\u003e\n```\n\n##### Loops\n\n###### Example # 1 A list of menu\n```php\n$html = '\n    Title\n    \u003cul\u003e\n        \u003c!-- BEGIN menu --\u003e\n        \u003cli\u003e\u003ca href=\"[URL]\"\u003e[TITLE]\u003c/a\u003e\u003c/li\u003e\n        \u003c!-- END menu --\u003e\n    \u003c/ul\u003e\n';\n \n$menu = array(\n    'home'    =\u003e 'Home',\n    'gallery' =\u003e 'Gallery',\n    'help'    =\u003e 'Help'\n);\n \n$tpl = new Mtpl();\n$tpl-\u003esetTemplate($html);\n \nforeach ($menu as $page_name =\u003e $title) {\n    $tpl-\u003emenu-\u003eassign('[URL]',  '?view=' . $page_name);\n    $tpl-\u003emenu-\u003eassign('[TITLE]', $title);\n    $tpl-\u003emenu-\u003ereassign();\n}\n \necho $tpl-\u003erender();\n```\nResult will look like:\n\n```html\nTitle\n\u003cul\u003e\n    \u003cli\u003e\u003ca href=\"?view=home\"\u003eHome\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"?view=gallery\"\u003eGallery\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"?view=help\"\u003eHelp\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n\n##### Fill drop down\n\n###### Example # 1 \n```php\n$html = '\n    \u003ch1\u003eTitle\u003c/h1\u003e\n    \u003cform\u003e\n        \u003cdiv class=\"form-group\"\u003e\n            \u003clabel for=\"year\"\u003eYear\u003c/label\u003e\n            \u003cselect id=\"year\" class=\"form-control\"\u003e\u003c/select\u003e\n        \u003c/div\u003e\n        \u003cbutton type=\"submit\" class=\"btn btn-primary\"\u003eSubmit\u003c/button\u003e\n    \u003c/form\u003e\n';\n\n$tpl = new Mtpl();\n$tpl-\u003esetTemplate($html);\n\n\n$years = array(\n    2000 =\u003e '2000',\n    2005 =\u003e '2005',\n    2010 =\u003e '2010',\n    2015 =\u003e '2015'\n);\n$tpl-\u003efillDropDown('year', $years, 2015);\n\n\necho $tpl-\u003erender();\n```\nResult will look like:\n\n```html\n    \u003ch1\u003eTitle\u003c/h1\u003e\n    \u003cform\u003e\n        \u003cdiv class=\"form-group\"\u003e\n            \u003clabel for=\"year\"\u003eYear\u003c/label\u003e\n            \u003cselect id=\"year\" class=\"form-control\"\u003e\n                \u003coption value=\"2000\"\u003e2000\u003c/option\u003e\n                \u003coption value=\"2005\"\u003e2005\u003c/option\u003e\n                \u003coption value=\"2010\"\u003e2010\u003c/option\u003e\n                \u003coption value=\"2015\" selected=\"selected\"\u003e2015\u003c/option\u003e\n            \u003c/select\u003e\n        \u003c/div\u003e\n        \u003cbutton type=\"submit\" class=\"btn btn-primary\"\u003eSubmit\u003c/button\u003e\n    \u003c/form\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn2ref%2Fmicro_templater","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn2ref%2Fmicro_templater","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn2ref%2Fmicro_templater/lists"}