Размер файла: 11.51Kb
<html> <head> <meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" > <title> Chapter 7. Встроенные функции </title> <meta name = "generator" content = "DocBook XSL Stylesheets V1.75.1" > <link rel = "home" href = "index.html" title = "Руководство по Smarty" > <link rel = "up" href = "smarty.for.designers.html" title = "Part II. Smarty для дизайнеров шаблонов" > <link rel = "prev" href = "language.combining.modifiers.html" title = "Chapter 6. Комбинирование модификаторов" > <link rel = "next" href = "language.function.config.load.html" title = "{config_load}" > </head> <body bgcolor = "white" text = "black" link = "#0000FF" vlink = "#840084" alink = "#0000FF" > <div class = "navheader" > <table width = "100%" summary = "Navigation header" > <tr><th colspan = "3" align = "center" > Chapter 7. Встроенные функции </th></tr> <tr> <td width = "20%" align = "left" > <a accesskey = "p" href = "language.combining.modifiers.html" > Prev </a> </td> <th width = "60%" align = "center" > Part II. Smarty для дизайнеров шаблонов </th> <td width = "20%" align = "right" > <a accesskey = "n" href = "language.function.config.load.html" > Next </a> </td> </tr> </table> <hr> </div> <div class = "chapter" title = "Chapter 7. Встроенные функции" > <div class = "titlepage" ><div><div><h2 class = "title" > <a name = "language.builtin.functions" ></a> Chapter 7. Встроенные функции </h2></div></div></div> <div class = "toc" > <p><b> Table of Contents </b></p> <dl> <dt><span class = "sect1" ><a href = "language.builtin.functions.html#language.function.capture" > {capture} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.config.load.html" > {config_load} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.foreach.html" > {foreach},{foreachelse} </a></span></dt> <dd><dl> <dt><span class = "sect2" ><a href = "language.function.foreach.html#foreach.property.index" > .index </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.foreach.html#foreach.property.iteration" > .iteration </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.foreach.html#foreach.property.first" > .first </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.foreach.html#foreach.property.last" > .last </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.foreach.html#foreach.property.show" > .show </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.foreach.html#foreach.property.total" > .total </a></span></dt> </dl></dd> <dt><span class = "sect1" ><a href = "language.function.if.html" > {if},{elseif},{else} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.include.html" > {include} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.include.php.html" > {include_php} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.insert.html" > {insert} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.ldelim.html" > {ldelim},{rdelim} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.literal.html" > {literal} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.php.html" > {php} </a></span></dt> <dt><span class = "sect1" ><a href = "language.function.section.html" > {section},{sectionelse} </a></span></dt> <dd><dl> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.index" > index </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.index.prev" > index_prev </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.index.next" > index_next </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.iteration" > iteration </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.first" > first </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.last" > last </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.rownum" > rownum </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.loop" > loop </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.show" > show </a></span></dt> <dt><span class = "sect2" ><a href = "language.function.section.html#section.property.total" > total </a></span></dt> </dl></dd> <dt><span class = "sect1" ><a href = "language.function.strip.html" > {strip} </a></span></dt> </dl> </div> <p> В smarty включены несколько встроенных функций. Эти встроенные функции интегрированы в язык шаблонов. Нельзя создавать <a class = "link" href = "language.custom.functions.html" title = "Chapter 8. Пользовательские Функции" > пользовательские функции </a> с такими же названиями и вам не следует модифицировать встроенные функции. </p> <p> Некоторые эти функции имеют атрибут <em class = "parameter" ><code> assign </code></em> , который помещает результати их выполнения в переменную шаблона, вместо вывода в браузер, практически как функция <a class = "link" href = "language.custom.functions.html#language.function.assign" title = "{assign}" ><code class = "varname" > {assign} </code></a> . </p> <div class = "sect1" title = "{capture}" > <div class = "titlepage" ><div><div><h2 class = "title" style = " clear : both " > <a name = "language.function.capture" ></a> {capture} </h2></div></div></div> <p> <code class = "varname" > {capture} </code> используется для того, чтобы собрать результат обработки части шаблона между тэгами в какую-то переменную, вместо того, чтобы отобразить результат. Любое содержимое между <code class = "varname" > {capture name='foo'} </code> и <code class = "varname" > {/capture} </code> сохраняется в переменную, указанную в атрибуте <em class = "parameter" ><code> name </code></em> . </p> <p> Захваченные данные могут в дальнейшем использоваться в шаблоне при помощи специальной переменной <a class = "link" href = "language.variables.smarty.html#language.variables.smarty.capture" title = "{$smarty.capture}" ><em class = "parameter" ><code> $smarty.capture.foo </code></em></a> , где <span class = "quote" > “ <span class = "quote" > foo </span> ” </span> - значение, переданное атрибуту <em class = "parameter" ><code> name </code></em> . Если атрибут <em class = "parameter" ><code> name </code></em> не указан, то используется <span class = "quote" > “ <span class = "quote" > default </span> ” </span> , т.е. <em class = "parameter" ><code> $smarty.capture.default </code></em> . </p> <p> Функция <code class = "varname" > {capture} </code> поддерживает вложенность. </p> <div class = "informaltable" ><table border = "1" > <colgroup> <col align = "center" > <col align = "center" > <col align = "center" > <col align = "center" > <col> </colgroup> <thead><tr> <th align = "center" > Имя атрибута </th> <th align = "center" > Тип </th> <th align = "center" > Обязателен </th> <th align = "center" > По умолчанию </th> <th> Описание </th> </tr></thead> <tbody> <tr> <td align = "center" > name </td> <td align = "center" > string </td> <td align = "center" > Нет </td> <td align = "center" ><span class = "emphasis" ><em> default </em></span></td> <td> Имя блока для сохранения </td> </tr> <tr> <td align = "center" > assign </td> <td align = "center" > string </td> <td align = "center" > Нет </td> <td align = "center" ><span class = "emphasis" ><em> n/a </em></span></td> <td> Имя переменной для сохранения результатов </td> </tr> </tbody> </table></div> <div class = "note" title = "Внимание" style = " margin - left : 0.5in ; margin - right : 0.5in ; " > <h3 class = "title" > Внимание </h3> <p> Будте осторожны, сохраняя результат команды <a class = "link" href = "language.function.insert.html" title = "{insert}" ><code class = "varname" > {insert} </code></a> . Если вы используете <a class = "link" href = "caching.html" title = "Chapter 14. Кэширование" ><em class = "parameter" ><code> кэширование </code></em></a> и в области кэширования встречаются команды <a class = "link" href = "language.function.insert.html" title = "{insert}" ><code class = "varname" > {insert} </code></a> , то не сохраняйте данный вывод. </p> </div> <p> </p> <div class = "example" > <a name = "id2667002" ></a><p class = "title" ><b> Example 7.1. Сохранение вывода шаблона в указанный атрибут </b></p> <div class = "example-contents" ><pre class = "programlisting" > {* мы не хотим отображать тэг div, если его содержимое не отображается *} {capture name=banner} {include file='get_banner.tpl'} {/capture} {if $smarty.capture.banner ne ''} <div id="banner">{$smarty.capture.banner}</div> {/if} </pre></div> </div> <p><br class = "example-break" > </p> <div class = "example" > <a name = "id2667016" ></a><p class = "title" ><b> Example 7.2. Сохранение содержимого в переменную </b></p> <div class = "example-contents" > <p> Этот пример также демонстрирует функцию <a class = "link" href = "language.function.popup.html" title = "{popup}" ><code class = "varname" > {popup} </code></a> </p> <pre class = "programlisting" > {capture name=some_content assign=popText} Имя сервера: {$smarty.server.SERVER_NAME|upper}<br /> Адрес сервера: {$smarty.server.SERVER_ADDR}<br /> Ваш IP: {$smarty.server.REMOTE_ADDR}. {/capture} <a href="#" {popup caption='Информация о Сервере' text=$popText}>help</a> </pre> </div> </div> <p><br class = "example-break" > </p> <p> См. также <a class = "link" href = "language.variables.smarty.html#language.variables.smarty.capture" title = "{$smarty.capture}" ><em class = "parameter" ><code> $smarty.capture </code></em></a> , <a class = "link" href = "language.function.eval.html" title = "{eval}" ><code class = "varname" > {eval} </code></a> , <a class = "link" href = "language.function.fetch.html" title = "{fetch}" ><code class = "varname" > {fetch} </code></a> , <a class = "link" href = "api.fetch.html" title = "fetch" ><code class = "varname" > fetch() </code></a> и <a class = "link" href = "language.custom.functions.html#language.function.assign" title = "{assign}" ><code class = "varname" > {assign} </code></a> . </p> </div> </div> <div class = "navfooter" > <hr> <table width = "100%" summary = "Navigation footer" > <tr> <td width = "40%" align = "left" > <a accesskey = "p" href = "language.combining.modifiers.html" > Prev </a> </td> <td width = "20%" align = "center" ><a accesskey = "u" href = "smarty.for.designers.html" > Up </a></td> <td width = "40%" align = "right" > <a accesskey = "n" href = "language.function.config.load.html" > Next </a> </td> </tr> <tr> <td width = "40%" align = "left" valign = "top" > Chapter 6. Комбинирование модификаторов </td> <td width = "20%" align = "center" ><a accesskey = "h" href = "index.html" > Home </a></td> <td width = "40%" align = "right" valign = "top" > {config_load} </td> </tr> </table> </div> </body> </html>