{"id":37006494,"url":"https://github.com/nixphp/view","last_synced_at":"2026-01-14T00:45:30.411Z","repository":{"id":291324469,"uuid":"977287725","full_name":"nixphp/view","owner":"nixphp","description":"NixPHP View Plugin for simple templating.","archived":false,"fork":false,"pushed_at":"2025-11-27T23:19:46.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-30T12:56:19.510Z","etag":null,"topics":["framework","nixphp","php","php8","plugin","templating","view"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nixphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-03T21:09:59.000Z","updated_at":"2025-07-28T21:19:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"b33046fa-cd57-4656-998a-0fd83f7062a5","html_url":"https://github.com/nixphp/view","commit_stats":null,"previous_names":["nixphp/view"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nixphp/view","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixphp","download_url":"https://codeload.github.com/nixphp/view/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fview/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["framework","nixphp","php","php8","plugin","templating","view"],"created_at":"2026-01-14T00:45:29.825Z","updated_at":"2026-01-14T00:45:30.402Z","avatar_url":"https://github.com/nixphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"text-align: center;\"\u003e\n\n![Logo](https://nixphp.github.io/docs/assets/nixphp-logo-small-square.png)\n\n[![NixPHP View Plugin](https://github.com/nixphp/view/actions/workflows/php.yml/badge.svg)](https://github.com/nixphp/view/actions/workflows/php.yml)\n\n\u003c/div\u003e\n\n[← Back to NixPHP](https://github.com/nixphp/framework)\n\n---\n\n# nixphp/view\n\n\u003e **A lightweight, native PHP templating system — with layout inheritance and block support.**\n\nThis plugin brings a clean, minimal templating system to your NixPHP application.\nIt lets you define base layouts, use content blocks, and safely output user data — all with pure PHP.\n\n\u003e 🧩 Part of the official NixPHP plugin collection.\n\u003e Install it when you need structured HTML rendering — without external engines like Twig or Blade.\n\n---\n\n## 📦 Features\n\n* ✅ Define layouts and reuse views via `setLayout()` and `block()/endblock()`\n* ✅ Render views with `view('template', [...])`\n* ✅ Return response objects with `render('template', [...])`\n* ✅ Safe output via `s()` (escape helper)\n* ✅ Fully native PHP – no new syntax or templating engine required\n\n---\n\n## 📥 Installation\n\n```bash\ncomposer require nixphp/view\n```\n\nThe plugin auto-registers itself and adds the `view()`, `render()`, `assets()` and `s()` helpers globally.\n\n---\n\n## 🚀 Usage\n\n### 🧱 Rendering views\n\nUse the `view()` helper to render a template and return the result as a **string**:\n\n```php\n$content = view('hello', ['name' =\u003e 'World']);\n```\n\nThis is useful if you want to process or wrap the HTML manually.\n\nUse the `render()` helper to return a **response object** instead (e.g. in your controller):\n\n```php\nreturn render('hello', ['name' =\u003e 'World']);\n```\n\nThis renders the view **and wraps it in a proper response**, ready to be returned from any route handler.\n\nTo load a template file in another folder, you can use the dot notation:\n```php\nreturn render('pages.hello', ['name' =\u003e 'World']);\n```\n\nOr even multiple levels:\n\n```php\nreturn render('pages.elements.hello', ['name' =\u003e 'World']);\n```\n\nThis works for both `view()` and `render()`.\n\n---\n\n### 🧩 Layouts \u0026 Blocks\n\nUse `setLayout()` to define a parent layout, and `block()/endblock()` to inject content:\n\n#### `app/views/page.phtml`\n\n```php\n\u003c?php $this-\u003esetLayout('layout') ?\u003e\n\n\u003c?php $this-\u003eblock('content') ?\u003e\n    \u003ch1\u003eHello \u003c?= s($name) ?\u003e!\u003c/h1\u003e\n\u003c?php $this-\u003eendblock('content') ?\u003e\n```\n\n#### `app/views/layout.phtml`\n\n```php\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003eMy App\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003c?= $this-\u003erenderBlock('content') ?\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n---\n\n### 🛡️ Escape output\n\nUse the `s()` helper to sanitize output (HTML-escaped):\n\n```php\n\u003cp\u003e\u003c?= s($userInput) ?\u003e\u003c/p\u003e\n```\n\n---\n\n## 🎨 Asset Management (CSS \u0026 JS)\n\nThe plugin includes a small, flexible asset collector used inside layouts to include CSS and JavaScript files.\n\nAssets are added inside views or controllers using the `assets()` helper:\n\n```php\nassets()-\u003eadd('/assets/style.css');            // CSS\nassets()-\u003eadd('/assets/app.js');               // JavaScript (classic)\nassets()-\u003eadd('/assets/main.js', 'module');    // JavaScript ES module\n```\n\n### Output in layout files\n\nUse `assets()-\u003erender('css')` or `assets()-\u003erender('js')` inside your layout:\n\n```php\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003c?= assets()-\u003erender('css') ?\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003c?= $this-\u003erenderBlock('content') ?\u003e\n    \u003c?= assets()-\u003erender('js') ?\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### What gets generated?\n\n**CSS:**\n\n```html\n\u003clink rel=\"stylesheet\" href=\"/assets/style.css\"\u003e\n```\n\n**Classic JS:**\n\n```html\n\u003cscript src=\"/assets/app.js\"\u003e\u003c/script\u003e\n```\n\n**Module JS:**\n\n```html\n\u003cscript type=\"module\" src=\"/assets/main.js\"\u003e\u003c/script\u003e\n```\n\n### Internals\n\n**All paths are automatically HTML-escaped via `s()`.**\n\n---\n\n\n## 🔁 Helper Comparison\n\n| Helper     | Returns             | Use case                                |\n| ---------- | ------------------- | --------------------------------------- |\n| `render()` | `ResponseInterface` | Ideal for controller return values   |\n| `view()`   | `string`            | For manual output or further processing |\n| `assets()` | `string`            | Include CSS \u0026 JS files in layouts       |\n| `s()`      | `string`            | Escape output                           |\n\n---\n\n## 🔍 Internals\n\n* `view()` resolves and loads `.phtml` templates from `/app/views/` or any registered view path.\n* `setLayout()` nests the rendered content into a wrapper view.\n* Blocks are buffered and stored internally until rendered.\n\n---\n\n## ✅ Requirements\n\n* `nixphp/framework` \u003e= 1.0\n\n---\n\n## 📄 License\n\nMIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixphp%2Fview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixphp%2Fview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixphp%2Fview/lists"}