🔥码云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="plugins.naming.conventions.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="plugins.functions.html" accesskey="N">Next</a></td></tr></table> # Writing Plugins[编写插件] Plugins can be either loaded by Smarty automatically from the filesystem or they can be registered at runtime via one of the register_* API functions. They can also be unregistered by using unregister_* API functions. For the plugins that are registered at runtime, the name of the plugin function(s) does not have to follow the naming convention. If a plugin depends on some functionality provided by another plugin (as is the case with some plugins bundled with Smarty), then the proper way to load the needed plugin is this: Smarty既可自动从文件系统加载插件,也可在运行时通过register_* API函数注册插件。当然,也可以通过unregister_* API函数卸载已经载入的插件。 对于只在运行时注册的插件函数不必遵守命名约定。 如果某个插件依赖其它插件的某些功能(事实上,一些插件被绑定在Smarty中),那么可以通过如下方法加载需要的插件: | ~~~ <?phprequire_once $smarty->_get_plugin_filepath('function', 'html_options');?> ~~~ | |-----| As a general rule, Smarty object is always passed to the plugins as the last parameter with two exceptions: modifiers do not get passed the Smarty object at all. blocks get passed $repeat after the Smarty object to keep backwards compatibility to older versions of Smarty. 按照惯例,Smarty对象通常作为最后一个参数传递给插件,但有两个例外: 调节器不须接受Smarty对象的传递。 为了向前兼容旧版Smarty,[块插件](#)将$repeat排在Smarty对象后面作为最后一个参数($smarty作为倒数第二个参数)。 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="plugins.naming.conventions.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="plugins.functions.html" accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Naming Conventions <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">Template Functions 模板函数</td></tr></table>