块函数

void smarty_block_name (array $params, mixed $content, object &$smarty, boolean &$repeat)

    块函数的形式为:{func} .. {/func}。换句话说,它们包含了一个模板块并对该块的内容进行操作。块函数优先于同名的定制函数,也就是说,你不能同时有定制函数{func}以及块函数{func}..{/func}

    如果你嵌套了块函数,可以查出其父块函数是什么。这是通过访问$smarty->_tag_stack变量实现的。只要用var_dump()即可,其结构是很明显的。

例子16-5. 块函数

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     block.translate.php
 * Type:     block
 * Name:     translate
 * Purpose:  translate a block of text
 * -------------------------------------------------------------
 */
function smarty_block_translate($params$content, &$smarty, &$repeat)
{
    
// 只在关标记时输出
    
if(!$repeat){
        if (isset(
$content)) {
            
$lang $params['lang'];
            
// 进行一些关于$content的智能翻译
            
return $translation;
        }
    }
}
?>

    参见:register_block()unregister_block()