mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-27 02:11:37 +01:00
129 lines
3.5 KiB
XML
129 lines
3.5 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
|
|
<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 à partir du template
|
|
sont contenus dans le tableau associatif <parameter>$params</parameter>.
|
|
</para>
|
|
<para>
|
|
Le retour de la fonction sera substituée à la balise de fonction
|
|
du template (fonction <function>fetch</function> par exemple). Sinon,
|
|
la fonction peut simplement accomplir une autre tâche 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 celà.
|
|
</para>
|
|
<para>
|
|
Référez-vous aussi à :
|
|
<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 role="php">
|
|
<![CDATA[
|
|
<?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 façon suivante :
|
|
</para>
|
|
<programlisting>
|
|
Question: Will we ever have time travel?
|
|
Answer: {eightball}.
|
|
</programlisting>
|
|
<para>
|
|
<example>
|
|
<title>Fonction de plugin sans sortie</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?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
|
|
-->
|