mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			123 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			123 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
   <sect1 id="plugins.functions"><title>Les fonctions de templates</title>
 | 
						|
    <funcsynopsis>
 | 
						|
     <funcprototype>
 | 
						|
      <funcdef>void <function>smarty_function_<replaceable>name</replaceable></function></funcdef>
 | 
						|
      <paramdef>array <parameter>$params</parameter></paramdef>
 | 
						|
      <paramdef>object <parameter>&$smarty</parameter></paramdef>
 | 
						|
     </funcprototype>
 | 
						|
    </funcsynopsis>
 | 
						|
    <para>
 | 
						|
    Tous les attributs passés aux fonctions de template a partir du template
 | 
						|
    sont contenus dans le tableau associatif <parameter>$params</parameter>.
 | 
						|
    Vous pouvez accéder a ces valeurs soit directement, par exemple
 | 
						|
    <varname>$params['start']</varname>, soit en utilisant
 | 
						|
    <varname>extract($params)</varname> pour les importer dans la table
 | 
						|
    des symboles.
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
    Le retour de la fonction sera substituée a la balise de fonction
 | 
						|
    du template (fonction <function>fetch</function> par exemple). Sinon,
 | 
						|
    la fonction peut simplement accomplir une autre tGche sans sortie
 | 
						|
    (la fonction <function>assign</function> par exemple)
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
    Si la fonction a besoin d'assigner des variables aux templates ou d'utiliser
 | 
						|
    d'autres fonctionnalités fournies par Smarty, elle peut recevoir un
 | 
						|
    objet <parameter>$smarty</parameter> pour cela.
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
     Référez-vous aussi a :
 | 
						|
     <link linkend="api.register.function">register_function()</link>,
 | 
						|
     <link linkend="api.unregister.function">unregister_function()</link>.
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
     <example>
 | 
						|
      <title>fonction de plugin avec sortie</title>
 | 
						|
      <programlisting>
 | 
						|
<?php
 | 
						|
/*
 | 
						|
 * Smarty plugin
 | 
						|
 * -------------------------------------------------------------
 | 
						|
 * Fichier :  function.eightball.php
 | 
						|
 * Type :     fonction
 | 
						|
 * Nom :      eightball
 | 
						|
 * Rôle :     renvoie une phrase magique au hasard
 | 
						|
 * -------------------------------------------------------------
 | 
						|
 */
 | 
						|
function smarty_function_eightball($params, &$smarty)
 | 
						|
{
 | 
						|
    $answers = array('Yes',
 | 
						|
                     'No',
 | 
						|
                     'No way',
 | 
						|
                     'Outlook not so good',
 | 
						|
                     'Ask again soon',
 | 
						|
                     'Maybe in your reality');
 | 
						|
 | 
						|
    $result = array_rand($answers);
 | 
						|
    return $answers[$result];
 | 
						|
}
 | 
						|
?></programlisting>
 | 
						|
     </example>
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
     peut être utilisée dans le template de la faton suivante :
 | 
						|
    </para>
 | 
						|
    <programlisting>
 | 
						|
Question: Will we ever have time travel?
 | 
						|
Answer: {eightball}.</programlisting>
 | 
						|
    <para>
 | 
						|
     <example>
 | 
						|
      <title>fonction de plugin sans sortie</title>
 | 
						|
      <programlisting>
 | 
						|
<?php
 | 
						|
/*
 | 
						|
 * Smarty plugin
 | 
						|
 * -------------------------------------------------------------
 | 
						|
 * Fichier :  function.assign.php
 | 
						|
 * Type :     fonction
 | 
						|
 * Nom :      assign
 | 
						|
 * Purpose :  assigne une valeur a une variable de template
 | 
						|
 * -------------------------------------------------------------
 | 
						|
 */
 | 
						|
function smarty_function_assign($params, &$smarty)
 | 
						|
{
 | 
						|
    extract($params);
 | 
						|
 | 
						|
    if (empty($var)) {
 | 
						|
        $smarty->trigger_error("assign: missing 'var' parameter");
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    if (!in_array('value', array_keys($params))) {
 | 
						|
        $smarty->trigger_error("assign: missing 'value' parameter");
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    $smarty->assign($var, $value);
 | 
						|
}
 | 
						|
?></programlisting>
 | 
						|
     </example>
 | 
						|
    </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
 | 
						|
--> |