🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
<table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="language.function.block.html" accesskey="P">Prev</a></td> <td width="50%" align="center" valign="bottom">Chapter 7. Built-in Functions[第七章.内置函数]</td> <td width="25%" align="right" valign="bottom"><a href="language.function.capture.html" accesskey="N">Next</a></td></tr></table> # {call} 调用 {call} is used to call a template function defined by the {function} tag just like a plugin function. Otherwise you can directly use the function as {funcname ...} in the template. * The {call} tag must have the name attribute which contains the name of the template function. * Values for variables can be passed to the template function as attributes. {call}用来调用[{function}](#)标签定义的模板函数,类似于插件函数。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> Template functions are defined global. Since the Smarty compiler is a single-pass compiler, The {call} tag must be used to call a template function defined externally from the given template.<br/> 模板函数具全局作用域,因为Smarty编译器是单进程的编译器,{call}标签必须用来调用给定的外部模板定义的模板函数。</td> </tr></table> 另外你可以在模板中直接使用{funcname...}函数。 {call}标签的属性名须包含模板函数的名称; 变量值可以通过模板函数作为属性传递。 **Attribute: ** | Attribute Name | Type | Required | Default | Description | |-----|-----|-----|-----|-----| | name | string | yes | *n/a* | The name of the template function | | assign | string | no | n/a | The name of the variable that the output of called template function will be assigned to | | [var...] | [var type] | no | n/a | variable to pass local to template function | **option flags:** | **Name** | **Description** | |-----|-----| | nocache | Cakk the template function in nocache mode | **属性: ** | 属性名 | 类型 | 是否必须 | 缺省值 | 描述 | |-----|-----|-----|-----|-----| | name | string | yes | *n/a* | 模板函数名称 | | assign | string | no | n/a | (模板函数的结果被贮存而不显示),分配的输出变量名 | | [var...] | [变量类型] | no | n/a | 传递给本地的模板函数变量 | **选项标签:** | **名称** | **描述** | |-----|-----| | nocache | 调用的模板函数为无缓存模式 | <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <a name="AEN2720" id="AEN2720"> </a> <b>Example 7.20. Calling a recursive menu example<br/> 例 7-20.调用递归菜单例子</b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p> {* define the function *} {* 定义函数 *} <br/> {function name=menu level=0}<br/> &lt;ul class="level{$level}"&gt;<br/> {foreach $data as $entry}<br/> {if is_array($entry)}<br/> &lt;li&gt;{$entry@key}&lt;/li&gt;<br/> {call name=menu data=$entry level=$level+1}<br/> {else}<br/> &lt;li&gt;{$entry}&lt;/li&gt;<br/> {/if}<br/> {/foreach}<br/> &lt;/ul&gt;<br/> {/function}</p> <p><br/> {* create an array to demonstrate *}{*创建一个演示数组*}<br/> {$menu = ['item1','item2','item3' =&gt; ['item3-1','item3-2','item3-3' =&gt;['item3-3-1','item3-3-2']],'item4']}<br/> {* run the array through the function *}<br/> {call name=menu data=$menu}<br/> {call menu data=$menu} {* short-hand *}<br/><br/> Will generate the following output</p> <p>* item1<br/> * item2<br/> * item3<br/> --o item3-1<br/> --o item3-2<br/> --o item3-3<br/> ----+ item3-3-1<br/> ----+ item3-3-2<br/> * item4<br/></p></td> </tr></table> See also {function}<br/> 参见<a href="language.function.function.html">{function}</a></div></td> </tr></table> <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="language.function.block.html" accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="language.function.capture.html" accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">{block}<br/> 块</td><td width="34%" align="center" valign="top"><a href="language.builtin.functions.html" accesskey="U">Up</a></td><td width="33%" align="right" valign="top">{capture}</td></tr></table>