html - 在 Smarty 中缩小 HTML 输出

标签 html compression smarty minify

如何在 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/

相关文章:

smarty - 如何在prestashop前端自定义模块中调用ajax

html - 视差+固定菜单问题

PHP将位数组压缩为可能的最短字符串

java - 用PHP压缩的字符串与用Java压缩的字符串不匹配

php - Shopware 5.2.11 在我的插件中包含 JavaScript

php - Smarty:同一行显示不止一次

javascript - 如何防止 popover div 在 twitter bootstrap "dismissible popover"(数据触发 ="focus")中点击时隐藏?

javascript - 使用 jQuery 将 Class 添加到 div 中的前 5 个元素

html - 从 UIImage 数据创建 URL

javascript - ZLIB 解压缩 - 客户端