苏州网站建设在fastadmin框架制作的插件个人中心样式时发现网站模板中使用了{__STYLE__}与{__SCRIPT__}被原样输出了,这不对劲啊,这原样输出不就是没解析模板么,我翻找了一下官方的cms找到了解决方法,以下为修改步骤:

在前端控制器的公共控制器中增加以下代码:
public function _initialize()
{
parent::_initialize();
Hook::add('view_filter',function (& $content){
$style = '';
$script = '';
$result = preg_replace_callback("/<(script|style)s(data-render="(script|style)")([sS]*?)>([sS]*?)</(script|style)>/i", function ($match) use (&$style, &$script) {
if (isset($match[1]) && in_array($match[1], ['style', 'script'])) {
${$match[1]} .= str_replace($match[2], '', $match[0]);
}
return '';
}, $content);
$content = preg_replace_callback('/^s+({__STYLE__}|{__SCRIPT__})s+$/m', function ($matches) use ($style, $script) {
return $matches[1] == '{__STYLE__}' ? $style : $script;
}, $result ? $result : $content);
});
}








