Files
smarty/docs/ja/programmers/api-functions/api-fetch.xml
2009-06-14 07:23:39 +00:00

160 lines
4.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 2972 Maintainer: takagi Status: ready -->
<!-- CREDITS: mat-sh,daichi,joe -->
<refentry id="api.fetch">
<refnamediv>
<refname>fetch()</refname>
<refpurpose>テンプレートの出力を返します。</refpurpose>
</refnamediv>
<refsect1>
<title>説明</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>
これは、テンプレートを
<link linkend="api.display">表示する</link>
のではなくその出力を返します。第1パラメータには、有効な
<link linkend="template.resources">テンプレートリソース</link>
の種類を含んだパスを指定する事ができます。任意の第2パラメータには
<parameter>キャッシュID</parameter> を渡す事ができます。
詳細は、<link linkend="caching">キャッシュの項目</link> を参照してください。
</para>
&parameter.compileid;
<para>
<example>
<title>fetch()</title>
<programlisting role="php">
<![CDATA[
<?php
include('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
// キャッシュが存在しない場合はデータベースを呼び出します
if(!$smarty->is_cached('index.tpl')) {
// ダミーデータを用意
$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);
}
// 出力を取り込みます
$output = $smarty->fetch('index.tpl');
// ここで$outputについて何かの処理を行います
echo $output;
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Email の送信に fetch() を使用する</title>
<para>
<filename>email_body.tpl</filename> テンプレート
</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}/login/
List master
Some user group
{include file='email_disclaimer.tpl'}
]]>
</programlisting>
<para>
<link linkend="language.function.textformat">
<varname>{textformat}</varname></link> 修飾子を用いた
<filename>email_disclaimer.tpl</filename>
</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>
PHP の
<ulink url="&url.php-manual;function.mail">
<varname>mail()</varname></ulink> 関数を用いたPHPスクリプト
</para>
<programlisting role="php">
<![CDATA[
<?php
// pear や 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>
<link linkend="language.function.fetch"><varname>{fetch}</varname></link>
<link linkend="api.display"><varname>display()</varname></link>
<link linkend="language.function.eval"><varname>{eval}</varname></link>
および
<link linkend="api.template.exists"><varname>template_exists()</varname></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
-->