[Fwd: all PHP] proposed doc complement to modifier

bertrand Gugger <[email protected]> Tue, 29 Aug 2006 13:12:39 +0200
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
Hello,
This is a persistent question in irc ... so I proposed some extra 
paragraph in the Modifier chapter.
Lemme know what corrections or enhancements I could bring to it.

Cheers
--
toggg

-------- Original Message --------
Subject: 	all PHP
Date: 	Sat, 08 Jul 2006 09:03:51 +0200
From: 	bertrand Gugger <[email protected]>
Reply-To: 	[email protected]
To: 	Peter Morgan <[email protected]>



this sort of thing , don pedro
please , forward to messju , no adress here

kindly yours 
-- 
toggg

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
language-modifier-any_PHP.xml (text/xml, 2.6 KB)
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
 <sect1 id="language.modifier.any_PHP">
  <title>any PHP function</title>
  <para>
     A modifier is a function used to transform a value.
  </para>

  <para>
  Any function can be used as modifier.
  That includes Smarty modifiers but also basic PHP functions.
  </para>


  <example>
   <title>strtoupper</title>
   <para>
    Example <literal>strtoupper</literal> piped after the variable
    as <literal>{$name|strtoupper}</literal> acts as in php.
   </para>
   <programlisting role="php">
<![CDATA[
<?php

$smarty->assign('name', 'Smarty');

?>
]]>
   </programlisting>
   <para>
    Where template is:
   </para>
   <programlisting>
<![CDATA[
{$name}<br/>
{$name|strtoupper}
]]>
   </programlisting>
   <para>
    This will output:
   </para>
   <screen>
<![CDATA[
Smarty<br/>
SMARTY
]]>
   </screen>
  </example>

  <para>
  The modifier always take the value before pipe as first argument.
  Most often it is the (Smarty assigned) variable.
  Further arguments follow function name with semicoluns.
  Let's cut our $name.
  </para>


  <example>
   <title>substr</title>
   <para>
    Example <literal>substr</literal> piped after the variable
    as <literal>{$name|substr:s:l}</literal> acts as in php, cut from <emphasis>s</emphasis> length <emphasis>l</emphasis>
   </para>
   <programlisting>
<![CDATA[
{$name|substr:1:3}
]]>
   </programlisting>
   <para>
    Outputs:
   </para>
   <screen>
<![CDATA[
mart
]]>
   </screen>
  </example>

  <para>
  Sometimes the first argument is not the Smarty assigned variable.
  Let's repeat our $name for 60 chars
  </para>

  <example>
   <title>str_pad</title>
   <para>
    Example <literal>str_pad</literal> piped before the variable
    as <literal>{""|str_pad:60:$name}</literal> acts as in php, pads '' with $name length 60
   </para>
   <programlisting>
<![CDATA[
{""|str_pad:60:$name}
]]>
   </programlisting>
   <para>
    Outputs:
   </para>
   <screen>
<![CDATA[
SmartySmartySmartySmartySmartySmartySmartySmartySmartySmarty
]]>
   </screen>
  </example>
   <para>See also <link linkend="language.modifier.upper">upper</link> </para>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->