Files
smarty/docs/fr/programmers/api-functions/api-register-function.xml
2006-10-07 21:01:42 +00:00

88 lines
2.5 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<!-- EN-Revision: 1.9 Maintainer: yannick Status: ready -->
<refentry id="api.register.function">
<refnamediv>
<refname>register_function()</refname>
<refpurpose>Déclare dynamiquement des plugins de fonction de templates</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>void</type><methodname>register_function</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>mixed</type><parameter>impl</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>cacheable</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>cache_attrs</parameter></methodparam>
</methodsynopsis>
<para>
Il faut passer en paramètres le nom de la <link linkend="plugins.functions">fonction
de templates</link>, suivi par le nom de la fonction PHP qui l'implémente.
</para>
&api.register.snippet;
<para>
Les paramètres <parameter>cacheable</parameter> et
<parameter>cache_attrs</parameter> peut être omis dans la
plupart des cas. Voir <link
linkend="caching.cacheable">Contrôler la mise en cache des sorties des Plugins</link>
pour plus d'informations concernant cette utilisation.
</para>
<example>
<title>Exemple avec register_function()</title>
<programlisting role="php">
<![CDATA[
<?php
$smarty->register_function('date_now', 'print_current_date');
function print_current_date ($params) {
extract($params);
if(empty($format))
$format="%b %e, %Y";
echo strftime($format,time());
}
?>
]]>
</programlisting>
<para>
Où le template est :
</para>
<programlisting>
<![CDATA[
{date_now}
{* ou, formaté différemment *}
{date_now format="%Y/%m/%d"}
]]>
</programlisting>
</example>
<para>
Voir aussi
<link linkend="api.unregister.function"><varname>unregister_function()</varname></link> et
les <link linkend="plugins.functions">plugins de fonction</link>.
</para>
</refsect1>
</refentry>
<!-- 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
-->