Files
smarty/docs/fr/programmers/plugins/plugins-modifiers.xml

117 lines
3.3 KiB
XML
Raw Normal View History

2004-04-13 11:47:32 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2004-12-26 20:05:31 +00:00
<!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
<sect1 id="plugins.modifiers">
<title>Modificateurs</title>
<para>
Les modificateurs sont des petites fonctions appliqu<71>es <20> une variable
de template avant qu'elle ne soit affich<63>e ou utilis<69>e dans un autre contexte.
Les modificateurs peuvent <20>tre cha<68>n<EFBFBD>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<61>tre pass<73> au modificateur est la valeur
sur laquelle le modificateur est suppos<6F> op<6F>rer. Les autres param<61>tres
peuvent <20>tre optionnels, d<>pendant de quel genre d'op<6F>ration doit <20>tre
effectu<74>.
</para>
<para>
Le modificateur doit retourner le r<>sultat de son ex<65>cution.
</para>
<para>
Lisez <20>galement
<link linkend="api.register.modifier">register_modifier()</link> et
2004-05-23 15:50:53 +00:00
<link linkend="api.unregister.modifier">unregister_modifier()</link>.
2004-12-26 20:05:31 +00:00
</para>
<example>
<title>Plugin modificateur simple</title>
<para>
Ce plugin est un alias d'une fonction PHP. Il n'a aucun param<61>tre
suppl<70>mentaires.
2004-05-23 15:50:53 +00:00
</para>
2004-12-26 20:05:31 +00:00
<programlisting role="php">
<![CDATA[
<?php
2004-04-13 11:47:32 +00:00
/*
* 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);
}
2004-12-26 20:05:31 +00:00
?>
]]>
</programlisting>
</example>
<para></para>
<example>
<title>Un plugin modificateur un peu plus complexe</title>
<programlisting role="php">
<![CDATA[
<?php
2004-04-13 11:47:32 +00:00
/*
* 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;
}
2004-12-26 20:05:31 +00:00
?>
]]>
</programlisting>
</example>
</sect1>
2004-05-23 15:50:53 +00:00
<!-- 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
-->