mirror of
https://github.com/smarty-php/smarty.git
synced 2026-02-13 02:20:18 +01:00
108 lines
3.3 KiB
XML
108 lines
3.3 KiB
XML
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|||
|
|
<!-- $Revision$ -->
|
|||
|
|
<sect1 id="plugins.modifiers"><title>Modificateurs</title>
|
|||
|
|
<para>
|
|||
|
|
Les modificateurs sont des petites fonctions appliqu<71>es a 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 chaen<65>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>
|
|||
|
|
Regardez aussi
|
|||
|
|
<link linkend="api.register.modifier">register_modifier()</link>,
|
|||
|
|
<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<61>tre
|
|||
|
|
suppl<70>mentaires.
|
|||
|
|
</para>
|
|||
|
|
<programlisting>
|
|||
|
|
<?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>
|
|||
|
|
<?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
|
|||
|
|
-->
|