tags:

views:

53

answers:

3

Is there a way to tell Smarty from PHP that you want it to strip all the whitespace in your templates before sending to browser, as if all your templates were embedded in {strip} tags? Some sort of Smarty object parameter or something?

A: 

You could create and register an output filter to do this; in the output filter, you can use for example this function to strip out unneeded whitespace.

Piskvor
A: 

Here is another output filter to strip white space.

http://www.smarty.net/forums/viewtopic.php?t=25&sid=26a10d55ac90d50dca7914e33fdc6fa1

Martin York
+1  A: 

In your Smarty plugin folder there is a filter that can be easily adapted to the task: it's outputfilter.trimwhitespace.php.

Just add the line

$source = preg_replace("`\s+`ms", " ", $source); 

(from the forum post linked by Martin) at line 51 and then call the output filter.

The advantage is that said filter does a nice job of saving and then restoring the code blocks where you might want to leave whitespace alone - inside script, pre and textarea elements (I'dd add the code element to the list, too).

djn