如何在 Smarty 中缩小所有输出的 HTML 模板?
像这样:
$smarty->minify = true;
P.S :我找到了 {strip}
函数,但我应该在我所有的 .tpl
文件中使用这个函数。我有很多 .tpl
文件,这种方式对我来说是不可能的。
最佳答案
我使用了这段代码:
function minify_html($tpl_output, Smarty_Internal_Template $template) {
$tpl_output = preg_replace('![\t ]*[\r\n]+[\t ]*!', '', $tpl_output);
return $tpl_output;
}
// register the outputfilter
$smarty->registerFilter("output", "minify_html");
$smarty->display($template);
注意:您需要将//comments
更改为SCRIPT 标签以/* comments */
关于html - 在 Smarty 中缩小 HTML 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18673684/