mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
added strip variable modifier
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- added strip variable modifier, updated docs (Monte)
|
||||
- fixed access to $smarty.x variables as arrays. (Andrei)
|
||||
- fixed errors with example setup docs (Monte, Matthew
|
||||
Hagerty)
|
||||
|
@@ -1000,6 +1000,34 @@ OUTPUT:
|
||||
23.5787446
|
||||
23.58
|
||||
24</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.modifier.strip">
|
||||
<title>strip</title>
|
||||
<para>
|
||||
This replaces all repeated spaces, newlines and tabs with a single
|
||||
space, or with a supplied string.
|
||||
</para>
|
||||
<note>
|
||||
<title>Note</title>
|
||||
<para>
|
||||
If you want to strip blocks of template text, use the <link
|
||||
linkend="language.function.strip">strip function</link>.
|
||||
</para>
|
||||
</note>
|
||||
<example>
|
||||
<title>strip</title>
|
||||
<programlisting>
|
||||
{$articleTitle}
|
||||
{$articleTitle|strip}
|
||||
{$articleTitle|strip:"&nbsp;"}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
Grandmother of
|
||||
eight makes hole in one
|
||||
Grandmother of eight makes hole in one
|
||||
Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&nbsp;one</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.modifier.strip.tags">
|
||||
@@ -2539,20 +2567,27 @@ e-mail: jane@mydomain.com<p></programlisting>
|
||||
<sect1 id="language.function.strip">
|
||||
<title>strip</title>
|
||||
<para>
|
||||
Many times web designers
|
||||
run into the issue where white space and carriage returns
|
||||
affect the output of the rendered HTML (browser "features"), so you
|
||||
must run all your tags together in the template to get the
|
||||
desired results. This usually ends up in unreadable or
|
||||
Many times web designers run into the issue where white space and
|
||||
carriage returns affect the output of the rendered HTML (browser
|
||||
"features"), so you must run all your tags together in the template
|
||||
to get the desired results. This usually ends up in unreadable or
|
||||
unmanagable templates.
|
||||
</para>
|
||||
<para>
|
||||
Anything within {strip}{/strip} tags in Smarty are stripped of
|
||||
the extra spaces or carriage returns at the beginnings and
|
||||
ends of the lines before they are displayed.
|
||||
This way you can keep your templates readable, and not worry
|
||||
about extra white space causing problems.
|
||||
Anything within {strip}{/strip} tags in Smarty are stripped of the
|
||||
extra spaces or carriage returns at the beginnings and ends of the
|
||||
lines before they are displayed. This way you can keep your
|
||||
templates readable, and not worry about extra white space causing
|
||||
problems.
|
||||
</para>
|
||||
<note>
|
||||
<title>Technical Note</title>
|
||||
<para>
|
||||
{strip}{/strip} does not affect the contents of template variables.
|
||||
See the <link linkend="language.modifier.strip">strip modifier
|
||||
function</link>.
|
||||
</para>
|
||||
</note>
|
||||
<example>
|
||||
<title>strip tags</title>
|
||||
<programlisting>
|
||||
|
23
libs/plugins/modifier.strip.php
Normal file
23
libs/plugins/modifier.strip.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* Type: modifier
|
||||
* Name: strip
|
||||
* Purpose: Replace all repeated spaces, newlines, tabs
|
||||
* with a single space or supplied replacement string.
|
||||
* Example: {$var|strip} {$var|strip:" "}
|
||||
* Author: Monte Ohrt <monte@ispi.net>
|
||||
* Version: 1.0
|
||||
* Date: September 25th, 2002
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_modifier_strip($text, $replace = ' ')
|
||||
{
|
||||
return preg_replace('!\s+!', $replace, $text);
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
23
plugins/modifier.strip.php
Normal file
23
plugins/modifier.strip.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* Type: modifier
|
||||
* Name: strip
|
||||
* Purpose: Replace all repeated spaces, newlines, tabs
|
||||
* with a single space or supplied replacement string.
|
||||
* Example: {$var|strip} {$var|strip:" "}
|
||||
* Author: Monte Ohrt <monte@ispi.net>
|
||||
* Version: 1.0
|
||||
* Date: September 25th, 2002
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_modifier_strip($text, $replace = ' ')
|
||||
{
|
||||
return preg_replace('!\s+!', $replace, $text);
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
Reference in New Issue
Block a user