{"id":26796425,"url":"https://github.com/peterujah/php-router-template","last_synced_at":"2025-10-12T05:43:48.828Z","repository":{"id":57711859,"uuid":"500322832","full_name":"peterujah/php-router-template","owner":"peterujah","description":"A simple php class to help render template in routers and fix additional slash issue","archived":false,"fork":false,"pushed_at":"2022-11-15T18:42:27.000Z","size":67,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-15T01:37:31.342Z","etag":null,"topics":[],"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/peterujah.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":"2022-06-06T06:49:01.000Z","updated_at":"2023-09-24T03:47:27.000Z","dependencies_parsed_at":"2023-01-22T16:15:28.258Z","dependency_job_id":null,"html_url":"https://github.com/peterujah/php-router-template","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/peterujah/php-router-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-router-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-router-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-router-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-router-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterujah","download_url":"https://codeload.github.com/peterujah/php-router-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-router-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010328,"owners_count":26084738,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-03-29T18:18:40.365Z","updated_at":"2025-10-12T05:43:48.786Z","avatar_url":"https://github.com/peterujah.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-router-template\n\nA simple php class to help render template in routers and fix additional slash issue.\n\n### IMPORTANT\n\nYou do not have to install, download nor use this class, i wrote the class for my personal needs, the first time i starting using router in my project instead of old ways. The only important the about this class is `deep` method which fixed the issue with extra shlash as posted on stackoverflow question here [style disappear when i add slash / after route](https://stackoverflow.com/questions/64298425/style-disappear-when-i-add-slash-after-route)\n\nAnd making it easy for me to access any defined global variables within the template since am not using any php framework.\nSo please just ignore the project, even though i have claerly documented the class and showed usage sample, it because i like wasing my time on beautiful usles codes and likes to wrap all my ever writing functions is a class because i might need it again. What about composer installation? Yah i know, it free so i used.\n\n\nInstallation is super-easy via Composer:\n```md\ncomposer require peterujah/php-router-templete\n```\n\n# USAGES\n\nInitialize RouterTemplate with the necessary parameters and register your custom classes.\n\n```php \n$template = new \\Peterujah\\NanoBlock\\RouterTemplate(__DIR__, false);\n$template-\u003eaddUser(new User(User::LIVE))-\u003eaddFunc(new Functions())-\u003eaddConfig(new Config());\n```\n\nRender template by passing the directory deep method as the first parameter while optional options array will be the second parameter.\n```php\n$template-\u003eRender(\"home\")-\u003ewith($template-\u003edeep(1));\n```\n\nA shorthand to the above method should be using `withDept` method and only passing the directory dept integer as the first parameter while optional options array will be the second parameter.\n```php\n$template-\u003eRender(\"home\")-\u003eview(1);\n```\n\nUsing the class with [Bramus Router](https://github.com/bramus/router) or any other php router as you wish. Initialize your router instance\n```php \n$router = new \\Bramus\\Router\\Router();\n```\n\nRender hompage template using `with` and `deep` method.\n```php\n$router-\u003eget('/', function() use ($template) {\n    $template-\u003eBuild(\"home\")-\u003ewith($template-\u003edeep(0));\n});\n```\n\nRender hompage template using `view` method.\n```php\n$router-\u003eget('/', function() use ($template) {\n    $template-\u003eBuild(\"home\")-\u003eview(0);\n});\n```\n\nRender update product template with product id as the second url parameter.\n```php\n$router-\u003eget('/update/([a-zA-Z0-9]+)', function($id) use ($template) {\n    $template-\u003eBuild(\"product\")-\u003eview(1);\n    /*\n      Using with method below\n      $template-\u003eBuild(\"product\")-\u003ewith($template-\u003edeep(1));\n    */\n});\n```\n\nRender update product template with product id as second url parameter and passing additional options to the template.\n```php\n$router-\u003eget('/update/([a-zA-Z0-9]+)', function($id) use ($template) {\n    $template-\u003eBuild(\"product\")-\u003eview(1, [\n      \"foo\" =\u003e \"Our Foo\"\n      \"bar\" =\u003e \"Our Bar id {$id}\"\n    ]);\n});\n```\n\nAccessing all global variables within a template file `/router/product.php`.\n\n```php\n\u003c?php \n/*Secure template from unwanted access*/\n$ALLOW_ACCESS or die(\"Access Denied\");\n?\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\u003ctitle\u003eRouter template\u003c/title\u003e\n\u003c!-- Unbreakable css path --\u003e\n\u003clink href=\"\u003c?php echo $root;?\u003eassets/bootstrap/css/bootstrap.min.css\" rel=\"stylesheet\"/\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003ch1\u003eNews - \u003c?php echo $config::NAME;?\u003e\u003c/h1\u003e\n\u003c?php \n  /* Call Functions methods */\n  $func-\u003edoStuff();\n  \n  /* Call User methods */\n  $user-\u003edoAnything()\n  \n  /* Gets user information */\n  $person-\u003ename;\n  \n  /* Access options from template */\n  echo $self[\"foo\"];\n  \n   /* Project root directory */\n  echo $root;\n?\u003e\nUnbreakable image \n\u003cimg src=\"\u003c?php echo $root;?\u003eassets/image/foo.png\"/\u003e\n\nUnbreakable link \n\u003ca href=\"\u003c?php echo $root;?\u003enewpage\"\u003eA New Page\u003c/a\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-router-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterujah%2Fphp-router-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-router-template/lists"}