simplydi/simplytemplate
Composer 安装命令:
composer require simplydi/simplytemplate
包简介
Very simple native PHP templating
README 文档
README
This is a very simple native PHP templating system for small projects.
Notes
- suitable for small projects only; for more complexity use League Plate, Twig, Latte, etc.
- currently in development = prone to errors
- created for learning purpose
Usage
Create the template to render. Extend a layout using @extend=layoutName directive.
You can escape the variables using $this->esc($var).
// Template to render: "page.php" @extend=_layout <h1><?= $title ?></h1> <p><?= $content ?></p> <?= $this->esc("<p>hello</p>");?>
_layout.php:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?= $title ?></title> </head> <body> <header> this is header </header> <main> <?= $content ?> </main> <aside> <?php include('_sidebar.php') ?> </aside> <footer> footer here </footer> </body> </html>
To include any partial just use the php function include().
using the template engine to render:
<?php include_once 'vendor/autoload.php'; $templateDir = __DIR__ . '/views'; $templateExtension = 'php'; $template = new \SimplyDi\SimplyTemplate\Engine( $templateDir, $templateExtension ); $data = [ 'title' => 'My Page Title', 'content' => 'This is the main content of the page.', ]; // get the template html via renderer $output = $template->render('page', $data); echo $output; // outputs the html
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-04