slim/php-view
slim/php-view is a lightweight view renderer for Slim Framework 4 that uses plain PHP templates with no compilation step or custom syntax. It supports layouts and partials through the PhpRenderer class, making server-side rendering simple and fast for developers who prefer native PHP over template e...
ob_start()/include glue. "Adopting" it is a composer require, not a vendor commitment — treat it as a decision not to build a rendering layer, and not to take on Twig's dependency surface either.ViewRendererInterface + PSR-7 responses, so the blast radius of a later migration to Twig or Plates is confined to template syntax, not application code. That makes it a legitimate "start simple, upgrade if needed" bet.psr/http-message ^1.0 || ^2.0. Previously, any project already pinned to PSR-7 v2 (current Slim 4 installs, many PSR-7 implementations) could not install this without a Composer conflict. That blocker is gone, which strengthens rather than weakens the "smallest dependency surface" argument — the one hard constraint it imposes is now satisfied by both major PSR-7 lines.Adopt when:
psr/http-message 2.0 — no conflict, no override, no --ignore-platform-req hack.Look elsewhere when:
<?= $var ?> unless you discipline yourself. Twig auto-escapes; this does not. 3.4.0 does not touch this.Upgrade note: 3.4.0 is non-breaking and safe to take on a patch bump; the only effective change is that Composer will now resolve against psr/http-message 2.x where it previously could not. No template or application code changes are implied.
To executives: This is a free, MIT-licensed, deliberately minimal view layer that is already the default in the standard Slim project skeleton. It costs nothing to adopt, adds almost no dependency or supply-chain risk, is the fastest rendering path available, and saves roughly a sprint of integration work versus standing up Twig. The recent 3.4.0 release is a small compatibility patch — it removes an installation conflict with the current generation of PSR-7 HTTP libraries — rather than new capability, so it changes our risk read only at the margin: the project is maintained enough to keep pace with its dependency ecosystem, which is exactly the level of stewardship a package this small needs. The trade-off is unchanged: safety comes from developer discipline rather than framework defaults, so we pair adoption with a mandatory escaping helper and a lint rule. If it is ever abandoned, the code is small enough that forking is a routine maintenance task, not a crisis.
To engineering: Plain .phtml templates rendered through output buffering, with a single layout applied by wrapping the inner template's output. Two non-negotiables: (1) every dynamic value goes through an e()/htmlspecialchars helper — there is no auto-escaping and no sandbox; (2) never let user input select the template name, since the renderer resolves paths by appending .phtml and checking the filesystem. Pin the version (3.4.0 is a safe patch bump and unblocks psr/http-message 2.x projects that previously could not install it), add a CI check that greps for unescaped short-echo tags, and keep business logic out of templates by pre-shaping view models in the controller. If the template count or the number of non-PHP authors grows past a threshold we set now, we migrate to Twig — the interface boundary makes that a contained change.
How can I help you explore Laravel packages today?