mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-09 00:31:45 +01:00
118 lines
3.8 KiB
XML
118 lines
3.8 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<!-- $Revision$ -->
|
||
<!-- EN-Revision: 1.6 Maintainer: freespace Status: ready -->
|
||
<refentry id="api.display">
|
||
<refnamediv>
|
||
<refname>display()</refname>
|
||
<refpurpose>отображает шаблон</refpurpose>
|
||
</refnamediv>
|
||
<refsect1>
|
||
<title>Описание</title>
|
||
<methodsynopsis>
|
||
<type>void</type><methodname>display</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.fetch">fetch()</link>.
|
||
В качестве первого аргумента следуедует указать доступный тип и путь к
|
||
<link linkend="template.resources">ресурсу шаблона</link>.
|
||
В качестве второго необязательного аргумета, вы можете передать идентификатор
|
||
кэша.
|
||
См. раздел
|
||
<link linkend="caching">Кэширование</link>
|
||
для получения дополнительной информации.
|
||
</para>
|
||
¶meter.compileid;
|
||
<example>
|
||
<title>display()</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);
|
||
|
||
}
|
||
|
||
// выводим результат
|
||
$smarty->display("index.tpl");
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
<para>
|
||
Используйте синтаксис <link
|
||
linkend="template.resources">ресурсов шаблона</link> для отображения файлов
|
||
за пределами директории
|
||
<link linkend="variable.template.dir">$template_dir</link>.
|
||
</para>
|
||
<example>
|
||
<title>Пример работы функции display() с ресурсами шаблона</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
// абсолютный файловый путь
|
||
$smarty->display('/usr/local/include/templates/header.tpl');
|
||
|
||
// абсолютный файловый путь (тот же результат)
|
||
$smarty->display('file:/usr/local/include/templates/header.tpl');
|
||
|
||
// абсолютный файловый путь под Windows (префикс "file:" ОБЯЗАТЕЛЕН)
|
||
$smarty->display('file:C:/www/pub/templates/header.tpl');
|
||
|
||
// использование ресурса шаблона с именем "db"
|
||
$smarty->display('db:header.tpl');
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
<para>
|
||
См. также
|
||
<link linkend="api.fetch">fetch()</link>
|
||
и
|
||
<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
|
||
-->
|
||
|