juanchosl / templaterender
A small, lightweight tool in order to render templates
1.0.3
2024-06-23 02:25 UTC
Requires
- php: ^7.1 || ^8.0
- ext-fileinfo: *
- ext-mbstring: *
- juanchosl/datatransfer: ^1.0
Requires (Dev)
- phpstan/phpstan: 1.9.1
- phpunit/phpunit: 9.5.25
This package is auto-updated.
Last update: 2024-10-05 22:29:47 UTC
README
Description
A small, lightweight utility to render templates
Install
composer require juanchosl/templaterender
How use it
Load composer autoload and use the JuanchoSL\TemplateRender class
$template_render = new TemplateRender(TEMPLATES_DIR, 'tpl.php'); $templates_render->setVar('title','Title of the page'); echo $templates_render->render('index', ['subtitle' => 'This is a subtitle']);
On index.tpl.php we can have:
<h1><?= $this->getVar('title'); ?></h1> <h2><?= $this->getVar('subtitle'); ?></h2>
We can include other templates from the original templates using fetch method, for use menu.tpl.php
<h1><?= $this->getVar('title'); ?></h1> <h2><?= $this->getVar('subtitle'); ?></h2> <?php $this->fetch('menu'); ?>