strip

1.0 1.1 1.2 1.3

Removes the white-space at the beginning and end of each line, and also removes all line breaks

<?php
strip(string $mode = 'default')
  • mode: the stripping mode defines some rules to prevent harmful behavior on some types of content, currently the only special mode is js or javascript that ensures javascript line comments do not break the script

Examples

Example #1

index.tpl
{strip}
   spaces between words in a same line     
  - are not removed -    
     but    
   everything   
       else   
     is     
{/strip}

The above example will output:

spaces between words in a same line- are not removed -buteverythingelseis

If you have a template with inline-Javascript, the {strip} plugin might break your script if it contains line comments.
Take a look at this example:

index.tpl
{strip}
<script type="text/javascript">
    // say hello!
    alert("hello!");
</script>
{/strip}

This will render the output to:

<script type="text/javascript"> // say hello! alert("hello!"); </script>

The script is on a single line now, and since the first line is a comment, everything is treated as a comment. To avoid this, use the js parameter inside the {strip} plugin.

index.tpl
{strip js}
<script type="text/javascript">
    // say hello!
    alert("hello!");
</script>
{/strip}
  • This will remove all comments inside the script.
  • Be careful to code properly and end each instruction with a ;, otherwise it might become foo()bar() and the browser will most likely treat that as an error. Use JSLint to test your code if you have issues.