Avalon Templating Component.
Fast and easy templating., (*1)
This package can be installed via composer:, (*2)
composer require avalon/templating
There are two templating engines available for use:, (*3)
Basically the same as include 'myfile.php';
but returns the rendered view as
opposed to straight up outputting it., (*4)
Allows for extending other views and defining content blocks., (*5)
<!-- layouts/default.phtml --> <h1>My Layout</h1> <?=$this->getSection('content')?>
extend('layouts/default.phtml'); ?> startSection('pageTitle', 'My Page'); ?> startSection('content'); ?> View content here endSection(); ?>
This example uses the PHP Extended engine., (*6)
use Avalon\Templating\View; use Avalon\Templating\View\Engines\PhpExtended; // Instantiate the engine $engine = new PhpExtended; // Set it as the engine for the `View` singleton to use. View::setEngine($engine); // Add some paths to search for views in View::addPath('/path/to/views/directory'); View::addPath('/path/to/another/views/directory'); // Render a view View::render('my_view.phtml'); // Variables can also be passed to views like so: View::render('my_view.phtml', ['variableName' => 'Variable value']);