Files
smarty/docs/fr/programmers/api-functions/api-fetch.xml

158 lines
4.2 KiB
XML
Raw Normal View History

2004-04-13 11:47:32 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2005-12-04 21:46:10 +00:00
<!-- EN-Revision: 1.7 Maintainer: yannick Status: ready -->
2004-12-26 17:02:12 +00:00
<refentry id="api.fetch">
<refnamediv>
2005-12-04 21:46:10 +00:00
<refname>fetch()</refname>
<refpurpose>Retourne le r<>sultat du template</refpurpose>
2004-12-26 17:02:12 +00:00
</refnamediv>
<refsect1>
2005-12-04 21:46:10 +00:00
<title>Description</title>
2004-12-26 17:02:12 +00:00
<methodsynopsis>
<type>string</type><methodname>fetch</methodname>
<methodparam><type>string</type><parameter>template</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>cache_id</parameter></methodparam>
2005-12-04 21:46:10 +00:00
<methodparam choice="opt"><type>string</type><parameter>$compile_id</parameter>
</methodparam>
2004-12-26 17:02:12 +00:00
</methodsynopsis>
<para>
2005-12-04 21:46:10 +00:00
Utilis<69>e pour renvoyer le r<>sultat du template plut<75>t que de
l'<link linkend="api.display">afficher</link>.
2004-12-26 17:02:12 +00:00
Il faut passer un type et un chemin de <link
linkend="template.resources">ressource template</link>
valides. Vous pouvez passer un identifiant de cache en deuxi<78>me
param<61>tre. Reportez-vous <20> la section <link linkend="caching">cache
</link> pour plus de renseignements.
</para>
&parameter.compileid;
2005-12-04 21:46:10 +00:00
2004-12-26 17:02:12 +00:00
<para>
<example>
2005-12-04 21:46:10 +00:00
<title>Exemple avec fetch()</title>
2004-12-26 17:02:12 +00:00
<programlisting role="php">
<![CDATA[
<?php
2005-12-04 21:46:10 +00:00
include('Smarty.class.php');
2004-04-13 11:47:32 +00:00
$smarty = new Smarty;
$smarty->caching = true;
2004-12-26 17:02:12 +00:00
// ne fait un appel <20> la base de donn<6E>es que si le fichier
2004-04-13 11:47:32 +00:00
// de cache n'existe pas
2005-12-04 21:46:10 +00:00
if(!$smarty->is_cached('index.tpl'))
2004-04-13 11:47:32 +00:00
{
// quelques donn<6E>es
2005-12-04 21:46:10 +00:00
$address = '245 N 50th';
2004-04-13 11:47:32 +00:00
$db_data = array(
2005-12-04 21:46:10 +00:00
'Ville' => 'Lincoln',
'Pays' => 'Nebraska',
'Code postal' = > '68502'
2004-12-26 17:02:12 +00:00
);
2004-04-13 11:47:32 +00:00
2005-12-04 21:46:10 +00:00
$smarty->assign('Nom','Fred');
$smarty->assign('Adresse',$address);
2004-04-13 11:47:32 +00:00
$smarty->assign($db_data);
}
// r<>cup<75>re le r<>sultat
2005-12-04 21:46:10 +00:00
$output = $smarty->fetch('index.tpl');
2004-04-13 11:47:32 +00:00
2005-05-09 16:45:23 +00:00
// fait quelque chose avec $output ici
2004-04-13 11:47:32 +00:00
2004-12-26 17:02:12 +00:00
echo $output;
2005-12-04 21:46:10 +00:00
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Utilisation de fetch() pour envoyer un email</title>
<para>
Le template email_body.tpl
</para>
<programlisting>
<![CDATA[
Cher {$contact.name},
Bienvenu et merci d'<27>tre devenu membre de notre groupe d'utilisateur,
Cliquez sur le lien ci-dessous pour vous identifier avec votre nom d'utilisateur '{$contact.login_id}'
et vous pourrez utiliser nos forums.
http://{$smarty.server.SERVER_NAME}/index.php?page=login
Liste principale
Quelques groupes d'utilisateurs
{include file="email_disclaimer.tpl"}
]]>
</programlisting>
<para>
Le template email_disclaimer.tpl qui utilise le modificateur
<link linkend="language.function.textformat">{textformat}</link>.
</para>
<programlisting>
<![CDATA[
{textformat wrap=40}
Unless you are named "{$contact.name}", you may read only the "odd numbered
words" (every other word beginning with the first) of the message above. If you have
violated that, then you hereby owe the sender 10 GBP for each even
numbered word you have read
{/textformat}
]]>
</programlisting>
<para>
et le script PHP utilisant la fonction PHP
<ulink url="&url.php-manual;function.mail">mail()</ulink>
</para>
<programlisting role="php">
<![CDATA[
<?php
// R<>cup<75>ration du contact depuis une base de donn<6E>es eg utilisation de pear ou adodb
$query = 'select name, email, login_id from contacts where contact_id='.$contact_id;
$contact = $db->getRow($sql);
$smarty->assign('contact', $contact);
mail($contact['email'], 'Subject', $smarty->fetch('email_body.tpl'));
2004-12-26 17:02:12 +00:00
?>
]]>
</programlisting>
</example>
</para>
2005-05-09 16:45:23 +00:00
<para>
2005-12-04 21:46:10 +00:00
Voir aussi
2005-05-25 16:49:34 +00:00
<link linkend="language.function.fetch">{fetch}</link>
<link linkend="api.display">display()</link>,
<link linkend="language.function.eval">{eval}</link> et
<link linkend="api.template.exists">template_exists()</link>.
2005-05-09 16:45:23 +00:00
</para>
2004-12-26 17:02:12 +00:00
</refsect1>
</refentry>
2005-05-25 16:49:34 +00:00
2004-04-13 11:47:32 +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
2005-05-25 16:49:34 +00:00
-->