| 148 |
lars |
1 |
Writing Plugins {#plugins.writing}
|
|
|
2 |
===============
|
|
|
3 |
|
|
|
4 |
Plugins can be either loaded by Smarty automatically from the filesystem
|
|
|
5 |
or they can be registered at runtime via one of the register\_\* API
|
|
|
6 |
functions. They can also be unregistered by using unregister\_\* API
|
|
|
7 |
functions.
|
|
|
8 |
|
|
|
9 |
For the plugins that are registered at runtime, the name of the plugin
|
|
|
10 |
function(s) does not have to follow the naming convention.
|
|
|
11 |
|
|
|
12 |
If a plugin depends on some functionality provided by another plugin (as
|
|
|
13 |
is the case with some plugins bundled with Smarty), then the proper way
|
|
|
14 |
to load the needed plugin is this:
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
<?php
|
|
|
18 |
function smarty_function_yourPlugin(array $params, Smarty_Internal_Template $template)
|
|
|
19 |
{
|
|
|
20 |
// load plugin depended upon
|
|
|
21 |
$template->smarty->loadPlugin('smarty_shared_make_timestamp');
|
|
|
22 |
// plugin code
|
|
|
23 |
}
|
|
|
24 |
?>
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
As a general rule, the currently evaluated template\'s
|
|
|
29 |
Smarty\_Internal\_Template object is always passed to the plugins as the
|
|
|
30 |
last parameter with two exceptions:
|
|
|
31 |
|
|
|
32 |
- modifiers do not get passed the Smarty\_Internal\_Template object at
|
|
|
33 |
all
|
|
|
34 |
|
|
|
35 |
- blocks get passed `$repeat` after the Smarty\_Internal\_Template
|
|
|
36 |
object to keep backwards compatibility to older versions of Smarty.
|