mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			158 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			158 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
<!-- EN-Revision: 1.7 Maintainer: yannick Status: ready -->
 | 
						|
 | 
						|
<refentry id="api.fetch">
 | 
						|
 <refnamediv>
 | 
						|
  <refname>fetch()</refname>
 | 
						|
  <refpurpose>Retourne le résultat du template</refpurpose>
 | 
						|
 </refnamediv>
 | 
						|
 <refsect1>
 | 
						|
  <title>Description</title>
 | 
						|
  <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>
 | 
						|
   <methodparam choice="opt"><type>string</type><parameter>$compile_id</parameter>
 | 
						|
   </methodparam>
 | 
						|
  </methodsynopsis>
 | 
						|
  <para>
 | 
						|
   Utilisée pour renvoyer le résultat du template plutôt que de
 | 
						|
   l'<link linkend="api.display">afficher</link>.
 | 
						|
   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ème
 | 
						|
   paramètre. Reportez-vous à la section <link linkend="caching">cache
 | 
						|
   </link> pour plus de renseignements.
 | 
						|
  </para>
 | 
						|
  ¶meter.compileid;
 | 
						|
 | 
						|
  <para>
 | 
						|
   <example>
 | 
						|
    <title>Exemple avec fetch()</title>
 | 
						|
    <programlisting role="php">
 | 
						|
<![CDATA[
 | 
						|
<?php
 | 
						|
include('Smarty.class.php');
 | 
						|
$smarty = new Smarty;
 | 
						|
 | 
						|
$smarty->caching = true;
 | 
						|
 | 
						|
// ne fait un appel à la base de données que si le fichier
 | 
						|
// de cache n'existe pas
 | 
						|
if(!$smarty->is_cached('index.tpl'))
 | 
						|
{
 | 
						|
 | 
						|
    // quelques données
 | 
						|
    $address = '245 N 50th';
 | 
						|
    $db_data = array(
 | 
						|
                        'Ville' => 'Lincoln',
 | 
						|
                        'Pays' => 'Nebraska',
 | 
						|
                        'Code postal' = > '68502'
 | 
						|
    );
 | 
						|
 | 
						|
    $smarty->assign('Nom','Fred');
 | 
						|
    $smarty->assign('Adresse',$address);
 | 
						|
    $smarty->assign($db_data);
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
// récupère le résultat
 | 
						|
$output = $smarty->fetch('index.tpl');
 | 
						|
 | 
						|
// fait quelque chose avec $output ici
 | 
						|
 | 
						|
echo $output;
 | 
						|
?>
 | 
						|
]]>
 | 
						|
    </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'ê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ération du contact depuis une base de donné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'));
 | 
						|
 | 
						|
?>
 | 
						|
]]>
 | 
						|
    </programlisting>
 | 
						|
   </example>
 | 
						|
  </para>
 | 
						|
  <para>
 | 
						|
   Voir aussi
 | 
						|
   <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>.
 | 
						|
  </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
 | 
						|
--> |