avalon / templating
Avalon Templating Component.
dev-master / 2.0.x-dev
2016-07-06 06:15 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-12-21 17:48:33 UTC
README
Fast and easy templating.
Installation
This package can be installed via composer:
composer require avalon/templating
Engines
There are two templating engines available for use:
PHP
Basically the same as include 'myfile.php';
but returns the rendered view as
opposed to straight up outputting it.
PHP Extended
Allows for extending other views and defining content blocks.
<!-- layouts/default.phtml --> <h1>My Layout</h1> <?=$this->getSection('content')?>
<!-- my_view.phtml --> <?php $this->extend('layouts/default.phtml'); ?> <?php $this->startSection('pageTitle', 'My Page'); ?> <?php $this->startSection('content'); ?> View content here <?php $this->endSection(); ?>
Usage
This example uses the PHP Extended engine.
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']);