juanchosl / templaterender
A small, lightweight tool in order to render templates
1.0.4
2024-12-13 19:08 UTC
Requires
- php: ^7.1 || ^8.0
- ext-fileinfo: *
- ext-mbstring: *
- juanchosl/datatransfer: 1.0.*
Requires (Dev)
- phpstan/phpstan: 1.12.*
- phpunit/phpunit: 9.6.*
This package is auto-updated.
Last update: 2025-06-13 20:17:32 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'); ?>