made more of a point of php functions as modifiers

This commit is contained in:
pete_morgan
2006-03-25 09:22:56 +00:00
parent d6ea6e7f5a
commit 17453595bf

View File

@@ -3,34 +3,48 @@
<chapter id="language.modifiers"> <chapter id="language.modifiers">
<title>Variable Modifiers</title> <title>Variable Modifiers</title>
<para> <para>
Variable modifiers can be applied to variables, custom functions or strings. To Variable modifiers can be applied to
apply a modifier, specify the value followed by the <literal>|</literal> <link linkend="language.syntax.variables">variables</link>,
<link linkend="language.custom.functions">custom functions</link> or strings. To
apply a modifier, specify the value followed by a <literal>|</literal>
(pipe) and the modifier name. A modifier may accept additional parameters (pipe) and the modifier name. A modifier may accept additional parameters
that affect its behavior. These parameters follow the modifer name and are that affect its behavior. These parameters follow the modifer name and are
separated by <literal>:</literal> (colon). separated by a <literal>:</literal> (colon). Additionally
all php-functions can be used as modifiers implicitly; more below.
</para> </para>
<example> <example>
<title>modifier example</title> <title>modifier examples</title>
<programlisting> <programlisting>
<![CDATA[ <![CDATA[
{* apply modifier to a variable *} {* apply modifier to a variable *}
{$title|upper} {$title|upper}
{* modifier with parameters *} {* modifier with parameters *}
{$title|truncate:40:"..."} {$title|truncate:40:'...'}
{* apply modifier to a function parameter *} {* apply modifier to a function parameter *}
{html_table loop=$myvar|upper} {html_table loop=$myvar|upper}
{* with parameters *} {* with parameters *}
{html_table loop=$myvar|truncate:40:"..."} {html_table loop=$myvar|truncate:40:'...'}
{* apply modifier to literal string *} {* apply modifier to literal string *}
{"foobar"|upper} {'foobar'|upper}
{* using date_format to format the current date *} {* using date_format to format the current date *}
{$smarty.now|date_format:"%Y/%m/%d"} {$smarty.now|date_format:"%Y/%m/%d"}
{* apply modifier to a custom function *} {* apply modifier to a custom function *}
{mailto|upper address="me@domain.dom"} {mailto|upper address='smarty@example.com'}
{* using php's str_repeat *}
{'=':str_repeat:80}
{* php's count *}
{$myArray|@count}
{* php's shuffle on servers's ip *}
{$smarty.server.SERVER_ADDR|shuffle}
]]> ]]>
</programlisting> </programlisting>
</example> </example>
@@ -44,16 +58,15 @@
</para> </para>
<para> <para>
Modifiers can be autoloaded from your <link Modifiers can be autoloaded from your <link
linkend="variable.plugins.dir">$plugins_dir</link> (also see: linkend="variable.plugins.dir">$plugins_dir</link>
<link linkend="plugins.naming.conventions">Naming or can be registered explicitely with <link
Conventions</link>) or can be registered explicitely (see: <link linkend="api.register.modifier">register_modifier()</link>.</para>
linkend="api.register.modifier">register_modifier</link>).</para>
<para> <para>
Additionally All php-functions can be used as modifiers implicitly. (The
all php-functions can be used as modifiers implicitly. (The
<literal>@count</literal> example above actually uses php's <literal>@count</literal> example above actually uses php's
count() function and not a smarty-modifier). Using php-functions count() function and not a smarty-modifier). Using php-functions
as modifiers has two little pitfalls: First: Sometimes the order as modifiers has two little pitfalls: Firstly: Sometimes the order
of the function-parameters is not the desirable one of the function-parameters is not the desirable one
(<literal>{"%2.f"|sprintf:$float}</literal> actually works, but (<literal>{"%2.f"|sprintf:$float}</literal> actually works, but
asks for the more intuitive. For example:<literal>{$float|string_format:"%2.f"}</literal> asks for the more intuitive. For example:<literal>{$float|string_format:"%2.f"}</literal>