tgrj / tweb_view
minimalistic view engine
Requires
- php: >=8.0
- tgrj/tweb_core: >=0.0.3
Requires (Dev)
- phpunit/phpunit: ^12.0
This package is auto-updated.
Last update: 2026-03-03 19:48:26 UTC
README
minimalistic view engine
Background
I like the phtml() method of the package noodlehaus/dispatch. I still wanted to extend this method a bit. Thus this extra package.
Usage
While writing this, this package will provide the function tweb_render(template_file, variables), where you can either give an absolute path to a PHTML or PHP file, or a relative one, which is stored in the tweb view folder. No need for the extension, but if none is given, the method first will check if a PHTML files with this name exists, and then a check for PHP. Also you can pass an array with variables, which will be usable in the template.
tweb_view('home/home', ['title' => 'great site']);
It is also possible to use layouts by using a colon ':' in the template_file string like so:
tweb_view('base/layout:home/home', ['title' => 'great site']);
This will (recursive; even when giving something like 'layoutA:layoutB:template' as a string!) use the last given element in the colon-seperated string in the template before that. In the example the template 'home/home' will be used in the template 'base/layout', in which the variable $content should exist!. This variable will be the content of the rendered home/home template.
In the templates or in the variables array you can use the method e() as a wrapper for the htmlspecialchars() php method for security reasons.