sinevia / php-library-template
PHP 库模板
v1.4.0
2019-02-17 20:29 UTC
This package is auto-updated.
Last update: 2024-09-16 19:31:03 UTC
README
模板是一个简单但强大的单文件模板引擎。
特性
- 单文件。无外部依赖
- 无需学习新“语言”。使用熟悉的PHP语法。
- 默认模板扩展名 .phtml
安装
将以下内容添加到您的composer文件中
"require": { "sinevia/php-library-template": "1.*" },
功能
1) 从文件
\Sinevia\Template::fromFile($templateFilepath, $data = array());
2) 从字符串
\Sinevia\Template::fromString($templateString, $data = array());
3) 缓存
\Sinevia\Template::setCacheDirectory($cacheDirPath); \Sinevia\Template::setCache($key, $content, $options = array()); \Sinevia\Template::getCache($key, $options = array());
3) 辅助函数
\Sinevia\Template::minifyHtml($html); \Sinevia\Template::minifyCss($css); \Sinevia\Template::minifyJs($js);
使用方法
$html = \Sinevia\Template::fromString($templateContent, [ 'page_meta_description' => $pageMetaDescription, 'page_meta_keywords' => $pageMetaKeywords, 'page_meta_robots' => $pageMetaRobots, 'page_canonical_url' => $pageCanonicalUrl, 'page_title' => $pageTitle, 'page_content' => $pageContent, ]);
\Sinevia\Template::setCache('key','content',array( 'post'=>true, 'get'=>true, 'session'=>true, 'expires'=>3600 // Default ));
布局
- 模板文件
[layout::public/guest/layout.phtml]
CONTENT
- 布局文件
<?php echo $content; ?>