Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minify HTML outputs in Smarty

How can I minify all output HTML templates in Smarty?

like this way: $smarty->minify = true;

P.S : I found {strip} function but I should use this function in all of my .tpl files. I have many .tpl file and this way is not possible for me.

like image 320
MajAfy Avatar asked Dec 20 '22 00:12

MajAfy


1 Answers

I used this code:

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);

NOTE: you will need to change // comments into SCRIPT tags to /* comments */

like image 144
Alexander Suvorov Avatar answered Jan 11 '23 21:01

Alexander Suvorov