mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +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 access to $smarty.x variables as arrays. (Andrei)
|
||||||
- fixed errors with example setup docs (Monte, Matthew
|
- fixed errors with example setup docs (Monte, Matthew
|
||||||
Hagerty)
|
Hagerty)
|
||||||
|
@@ -1000,6 +1000,34 @@ OUTPUT:
|
|||||||
23.5787446
|
23.5787446
|
||||||
23.58
|
23.58
|
||||||
24</programlisting>
|
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>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.strip.tags">
|
<sect1 id="language.modifier.strip.tags">
|
||||||
@@ -2539,20 +2567,27 @@ e-mail: jane@mydomain.com<p></programlisting>
|
|||||||
<sect1 id="language.function.strip">
|
<sect1 id="language.function.strip">
|
||||||
<title>strip</title>
|
<title>strip</title>
|
||||||
<para>
|
<para>
|
||||||
Many times web designers
|
Many times web designers run into the issue where white space and
|
||||||
run into the issue where white space and carriage returns
|
carriage returns affect the output of the rendered HTML (browser
|
||||||
affect the output of the rendered HTML (browser "features"), so you
|
"features"), so you must run all your tags together in the template
|
||||||
must run all your tags together in the template to get the
|
to get the desired results. This usually ends up in unreadable or
|
||||||
desired results. This usually ends up in unreadable or
|
|
||||||
unmanagable templates.
|
unmanagable templates.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Anything within {strip}{/strip} tags in Smarty are stripped of
|
Anything within {strip}{/strip} tags in Smarty are stripped of the
|
||||||
the extra spaces or carriage returns at the beginnings and
|
extra spaces or carriage returns at the beginnings and ends of the
|
||||||
ends of the lines before they are displayed.
|
lines before they are displayed. This way you can keep your
|
||||||
This way you can keep your templates readable, and not worry
|
templates readable, and not worry about extra white space causing
|
||||||
about extra white space causing problems.
|
problems.
|
||||||
</para>
|
</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>
|
<example>
|
||||||
<title>strip tags</title>
|
<title>strip tags</title>
|
||||||
<programlisting>
|
<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