Files
smarty/docs/es/programmers/api-functions/api-fetch.xml
2005-11-08 23:37:29 +00:00

156 lines
3.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<refentry id="api.fetch">
<refnamediv>
<refname>fetch()</refname>
<refpurpose>Retorna la salida del template</refpurpose>
</refnamediv>
<refsect1>
<title>Descripción</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>
Este retorna la salida del template en vez de
<link linkend="api.display">desplegarla</link>.
Proporcionando un tipo y path valido
<link linkend="template.resources">template resource</link>.
Como un segundo parámetro opcional, usted puede pasar el
identificador de cache.
vea el <link linkend="caching">caching section</link> para
mayor información.
</para>
&parameter.compileid;
<para>
<example>
<title>fetch()</title>
<programlisting role="php">
<![CDATA[
<?php
include('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
// only do db calls if cache doesn't exist
if(!$smarty->is_cached('index.tpl')) {
// dummy up some data
$address = '245 N 50th';
$db_data = array(
'City' => 'Lincoln',
'State' => 'Nebraska',
'Zip' => '68502'
);
$smarty->assign('Name','Fred');
$smarty->assign('Address',$address);
$smarty->assign($db_data);
}
// capture the output
$output = $smarty->fetch('index.tpl');
// do something with $output here
echo $output;
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Usando fetch() y enviando a un e-mail</title>
<para>
El template email_body.tpl
</para>
<programlisting>
<![CDATA[
Dear {$contact.name},
Welcome and thankyou for signing up as a member of our user group,
Click on the link below to login with your user name of '{$contact.login_id}'
so you can post in our forums.
http://{$smarty.server.SERVER_NAME}/index.php?page=login
List master
Some user group
{include file="email_disclaimer.tpl"}
]]>
</programlisting>
<para>
El template email_disclaimer.tpl usando el modificador
<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>
y el script de PHP usando la función
<ulink url="&url.php-manual;function.mail">mail()</ulink>
</para>
<programlisting role="php">
<![CDATA[
<?php
// get contact from database eg using pear or 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>
Ver también
<link linkend="language.function.fetch">{fetch}</link>
<link linkend="api.display">display()</link>,
<link linkend="language.function.eval">{eval}</link>,
y
<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
-->