Download the PHP package splinter/view without Composer
On this page you can find all versions of the php package splinter/view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download splinter/view
More information about splinter/view
Files in splinter/view
Package view
Short Description Twig view rendering extension for the Splinter framework
License MIT
Informations about the package view
splinter/view
Twig view rendering extension for the Splinter framework.
This package adds optional Twig-based templating on top of Splinter's core, without changing the core itself. It provides:
- A
TwigServiceProviderregisteringTwig\Environmentand its filesystem loader in the DI container. - A
TwigExtensionInterfacefor adding custom Twig globals, filters, and functions without touching this package. - An
HtmlExceptionHandler, which replaces the core's defaultJsonExceptionHandlerand renders uncaught exceptions as HTML using Twig templates. - Stub files (config, error templates, a demo route and controller)
published into your application skeleton via
vendor:publish.
Installation
Add the provider to config/app.php:
Publish the package's config, error templates, demo route, and demo view into your application:
This copies:
| Source | Destination |
|---|---|
config/twig.php |
config/twig.php |
resources/views/errors/ |
resources/views/errors/ |
resources/views/hello.twig |
resources/views/hello.twig |
routes/web.php |
routes/web.php |
Existing files are skipped by default. Pass --force to overwrite them.
Configuration
config/twig.php:
| Key | Description |
|---|---|
views_path |
Directory Twig loads templates from. |
cache |
false, or a path to a directory for compiled template caching. |
auto_reload |
Whether Twig recompiles templates when the source file changes. |
extensions |
List of TwigExtensionInterface classes to apply to the environment. |
Adding custom Twig functions/filters
Implement TwigExtensionInterface:
Register it in config/twig.php → extensions. It is resolved from the
DI container, so constructor dependencies are autowired as usual.
HTML error pages
Once the provider is registered, ExceptionHandlerInterface resolves to
HtmlExceptionHandler automatically — the core's HttpKernel picks it
up without any further wiring.
HtmlExceptionHandler renders errors/{statusCode}.twig for the
resolved HTTP status code, falling back to errors/500.twig if a
specific template isn't found, and finally to a plain inline HTML
string if Twig itself fails to render.
Edit the published templates in resources/views/errors/ to match your
application's design.
Demo route
routes/web.php (published, not autoloaded — add it to
config/app.php → routes yourself):
It registers GET /hello, resolved to HelloController, rendering
resources/views/hello.twig. Use it to confirm the view stack renders
end-to-end, then remove it once you have real routes.
Requirements
- PHP ^8.2
- splinter/framework
- twig/twig ^3.8