mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-10-31 12:21:36 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			117 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| <?xml version="1.0" encoding="iso-8859-1"?>
 | |
| <!-- $Revision$ -->
 | |
| <!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
 | |
| <sect1 id="plugins.modifiers">
 | |
|  <title>Modificateurs</title>
 | |
|  <para>
 | |
|   Les modificateurs sont des petites fonctions appliquées à une variable
 | |
|   de template avant qu'elle ne soit affichée ou utilisée dans un autre contexte.
 | |
|   Les modificateurs peuvent être chaînés entre eux.
 | |
|  </para>
 | |
|  <funcsynopsis>
 | |
|   <funcprototype>
 | |
|    <funcdef>mixed <function>smarty_modifier_<replaceable>name</replaceable></function></funcdef>
 | |
|    <paramdef>mixed <parameter>$value</parameter></paramdef>
 | |
|    <paramdef>[mixed <parameter>$param1</parameter>, ...]</paramdef>
 | |
|   </funcprototype>
 | |
|  </funcsynopsis>
 | |
|  <para>
 | |
|   Le premier paramètre passé au modificateur est la valeur
 | |
|   sur laquelle le modificateur est supposé opérer. Les autres paramétres
 | |
|   peuvent être optionnels, dépendant de quel genre d'opération doit être
 | |
|   effectué.
 | |
|  </para>
 | |
|  <para>
 | |
|   Le modificateur doit retourner le résultat de son exécution.
 | |
|  </para>
 | |
|  <para>
 | |
|   Lisez également
 | |
|   <link linkend="api.register.modifier">register_modifier()</link> et
 | |
|   <link linkend="api.unregister.modifier">unregister_modifier()</link>.
 | |
|  </para>
 | |
|  <example>
 | |
|   <title>Plugin modificateur simple</title>
 | |
|   <para>
 | |
|    Ce plugin est un alias d'une fonction PHP. Il n'a aucun paramètre
 | |
|    supplémentaires.
 | |
|   </para>
 | |
|   <programlisting role="php">
 | |
| <![CDATA[
 | |
| <?php
 | |
| /*
 | |
|  * Smarty plugin
 | |
|  * -------------------------------------------------------------
 | |
|  * Fichier :  modifier.capitalize.php
 | |
|  * Type :     modificateur
 | |
|  * Name :     capitalize
 | |
|  * Rôle :     met une majuscule aux mots d'une phrase
 | |
|  * -------------------------------------------------------------
 | |
|  */
 | |
| function smarty_modifier_capitalize($string)
 | |
| {
 | |
|     return ucwords($string);
 | |
| }
 | |
| ?>
 | |
| ]]>
 | |
|   </programlisting>
 | |
|  </example>
 | |
|  <para></para>
 | |
|  <example>
 | |
|   <title>Un plugin modificateur un peu plus complexe</title>
 | |
|   <programlisting role="php">
 | |
| <![CDATA[
 | |
| <?php
 | |
| /*
 | |
|  * Smarty plugin
 | |
|  * -------------------------------------------------------------
 | |
|  * Fichier :  modifier.truncate.php
 | |
|  * Type :     modificateur
 | |
|  * Name :     truncate
 | |
|  * Rôle :     Tronque une chaene a une certaine longueur si
 | |
|  *            nécessaire, la coupe optionnellement au milieu
 | |
|  *            d'un mot et ajoute la chaene $etc 
 | |
|  * -------------------------------------------------------------
 | |
|  */
 | |
| function smarty_modifier_truncate($string, $length = 80, $etc = '...',
 | |
|                                   $break_words = false)
 | |
| {
 | |
|     if ($length == 0)
 | |
|         return '';
 | |
| 
 | |
|     if (strlen($string) > $length) {
 | |
|         $length -= strlen($etc);
 | |
|         $fragment = substr($string, 0, $length+1);
 | |
|         if ($break_words)
 | |
|             $fragment = substr($fragment, 0, -1);
 | |
|         else
 | |
|             $fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
 | |
|         return $fragment.$etc;
 | |
|     } else
 | |
|         return $string;
 | |
| }
 | |
| ?>
 | |
| ]]>
 | |
|   </programlisting>
 | |
|  </example>
 | |
| </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
 | |
|  -->
 |