Changing settings by template

通过你会通过修改Smarty 成员变量 来修改Smarty的设置。 此外,你还可以通过Smarty 函数 来注册插件、过滤器等等。 Smarty对象的修改将是全局的。

然而你也可以通过单独的模板对象来修改Smarty的成员变量或调用函数。 模板对象的修改将只会作用于当前模板和其包含的子模板。

Example 17.4. 创建模板对象并修改Smarty的设置


<?php
$tpl = $smarty->createTemplate('index.tpl');
$tpl->cache_lifetime = 600;
//或者
$tpl->setCacheLifetime(600);
$smarty->display($tpl);
?>

    


Example 17.5. 创建模板对象并注册插件


<?php
$tpl = $smarty->createTemplate('index.tpl');
$tpl->registerPlugin('modifier','mymodifier');
$smarty->display($tpl);
?>