<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="plugins.resources.html" accesskey="P">Prev</a></td> <td width="50%" align="center" valign="bottom">Chapter 16. Extending Smarty With Plugins</td> <td width="25%" align="right" valign="bottom"><a href="appendixes.html" accesskey="N">Next</a></td></tr></table> # Inserts[插入] Insert plugins are used to implement functions that are invoked by {insert} tags in the template. 插入插件用来执行在模板中被[{insert}](#)标签调用的函数 。 > string smarty_insert_name($params, &$smarty); array $params; object &$smarty; The first parameter to the function is an associative array of attributes passed to the insert. The insert function is supposed to return the result which will be substituted in place of the {insert} tag in the template. 函数的第一个参数作为一个属性的关联数组传递给insert。 插入函数有返回值,该值(内容)将替换模板中的[{insert}](#)标签。 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"><a name="AEN4178"/> <b><span class="PROGRAMLISTING">Example 16.11. insert plugin</span><br/> 例16-11.插入插件</b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="PROGRAMLISTING">&lt;?php/* * Smarty plugin * ------------------------------------------------------------- * File: insert.time.php * Type: time * Name: time * Purpose: Inserts current date/time according to format * ------------------------------------------------------------- */function smarty_insert_time($params, $smarty){ if (empty($params['format'])) { $smarty-&gt;triggerError("insert time: missing 'format' parameter"); return; } return strftime($params['format']);}?&gt;</pre></td></tr></table></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="plugins.resources.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="appendixes.html" accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Resources<br/> 资源</td> <td width="34%" align="center" valign="top"><a href="plugins.html" accesskey="U">Up</a></td> <td width="33%" align="right" valign="top">Appendixes<br/> 附属</td> </tr></table>