juanchosl/templaterender

一个用于渲染模板的小型轻量级工具

1.0.3 2024-06-23 02:25 UTC

This package is auto-updated.

Last update: 2024-09-05 22:16:40 UTC


README

描述

一个用于渲染模板的小型轻量级实用工具

安装

composer require juanchosl/templaterender

如何使用

加载composer自动加载并使用JuanchoSL\TemplateRender类

$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']);

index.tpl.php中,我们可以有

<h1><?= $this->getVar('title'); ?></h1>

<h2><?= $this->getVar('subtitle'); ?></h2>

我们可以使用fetch方法从原始模板中包含其他模板,例如使用menu.tpl.php

<h1><?= $this->getVar('title'); ?></h1>

<h2><?= $this->getVar('subtitle'); ?></h2>
<?php $this->fetch('menu'); ?>