ymj666 / think-smarty
ThinkPHP6/ThinkPHP8 的 Smarty 模板驱动
1.0.0
2024-07-11 12:48 UTC
Requires
- php: ^8.0
- smarty/smarty: ^5.0
- topthink/framework: ^6.0 || ^8.0
This package is auto-updated.
Last update: 2024-09-11 13:26:40 UTC
README
ThinkPHP6/ThinkPHP8 Smarty 模板引擎驱动,使用 Smarty5 作为模板引擎
安装
composer require ymj666/think-smarty
配置
配置文件沿用了 ThinkPHP 的 view.php 配置文件,要使用 think-smarty 请先将 view.php 中的 type 配置项修改为 ThinkSmarty::class
增加了以下配置项:
tpl_cache: 是否开启模板编译缓存,设为false则每次都会重新编译,默认为truetpl_cache_path: 模板编译缓存目录,对应 Smarty 的CompileDir配置,默认为runtime/tempdisplay_cache: 是否开启模板渲染缓存,设置为true则缓存过期前会直接读取渲染结果输出,默认为falsedisplay_cache_path: 模板渲染缓存目录,对应 Smarty 的CacheDir配置,默认为runtime/display_cachedisplay_cache_time: 模板渲染缓存有效期,单位:秒。设置为0则永不过期,默认为3600tpl_replace_string: 模板输出替换,是一个数组,格式为'原文本' => '替换的文本',如:'__STATIC__' => '/static'
更多配置项,请查看 ThinkSmarty.php
使用
在 Smarty 模板文件中可以直接使用 ThinkPHP 的部分助手函数,具体可查看 ThinkSmarty.php
cacheconfigcookieenvinputlangparse_namesessiontokentoken_fieldtoken_metaurlapp_pathbase_pathconfig_pathpublic_pathruntime_pathroot_path
相关链接
其他说明
代码参考了 ThinkPHP8 内置的 PHP 模板引擎