牛骨文教育服务平台(让学习变的简单)

register_block
注册一个块

void register_block (string name, mixed impl, bool cacheable, array or null cache_attrs)

Use this to dynamically register block functions plugins. Pass in the block function name, followed by the PHP function callback that implements it.

用来动态注册/定义块函数插件。前两个参数指定块函数名称和执行函数的名称。

The php-function callback impl can be either (a) a string containing the function name or (b) an array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string containing the mehod-name or (c) an array of the form array(&$class, $method) with $class being a classname and $method being a class method of that class.

执行函数的格式可以是一个包含函数名称的字符串;也可以是一个array(&$object, $method)数组形式,其中&$object是一个对象的引用,而$method是它的一个方法;还可以是一个array(&$ class, $method)数组形式,其中$class是一个类的名称,$method是类中的一个方法。

$cacheable and $cache_attrs can be omitted in most cases. See Controlling Cacheability of Plugins" Output on how to use them properly.

$cacheable$cache_attrs 参数在大多数情况下可以省略。它们的使用方法可以查看控制插件输出的缓存。

Example 13-21. register_block
例子 13-21. 注册一个块

/* PHP */
$smarty->register_block("translate", "do_translation");

function do_translation ($params, $content, &$smarty, &$repeat) {
if (isset($content)) {
$lang = $params["lang"];
// do some translation with $content
return $translation;
}
}

{* template *}
{translate lang="br"}
Hello, world!
{/translate}