xiaodi / think-template-magic
ThinkPHP 模板组件
v0.5.0
2019-11-23 05:10 UTC
Requires
- topthink/think-view: ^1.0
This package is auto-updated.
Last update: 2024-09-18 14:56:06 UTC
README
帮助你在模板上加点魔法
如果你的项目模板很多,难以维护,可以使用此工具添加(例如全局样式,javascript,广告等等)。
仅适用于 ThinkPHP 6.0
安装
$ composer require xiaodi/think-templte-magic
使用
示例 添加一个css
样式
<?php namespace app; use xiaodi\Contracts\TemplateMagicHandleInterface; use xiaodi\Contracts\TemplateMagicReplaceInterface; class Replace implements TemplateMagicHandleInterface { public function handle(TemplateMagicReplaceInterface $handle) { $handle->head('<link rel="stylesheet" href="https://static.kodcloud.com/index/js/lib/bootstrap-3.3.7/css/bootstrap.min.css">'); } }
配置
config/template_magic.php
use app\Replace; return [ 'handle' => Replace::class ]
支持闭包
use xiaodi\Contracts\TemplateMagicReplaceInterface; return [ 'handle' => function (TemplateMagicReplaceInterface $handle) { $handle->head('<link rel="stylesheet" href="https://static.kodcloud.com/index/js/lib/bootstrap-3.3.7/css/bootstrap.min.css">'); } ];
函数
$handle->head($content)
在</head>
标签前插入内容$handle->body($content)
在</body>
标签前插入内容