Force Caching of Insert-Plugins - Bug?
| From: | Thomas Schulz | Date: | Tue, 06 May 2003 16:36:29 +0000 |
| Subject: | Force Caching of Insert-Plugins - Bug? | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-1369@lists.php.net to get a copy of this message | ||
Hi,
I have implemented most of my application logic as insert-plugins. But in
some cases it is not necessary to prevent them from caching and the insert-
plugin could work like a template function.
To force caching of an insert plugin I wrote a little template function as
wrapper:
function smarty_function_static($params, &$smarty)
{
require_once MY_PLUGIN_DIR . 'insert.'.$params['name'].'.php';
$insert_function = 'smarty_insert_' . $params['name'];
return $insert_function($params, $smarty);
}
Some samples with an insert plugin named "content".
Show a content item and don't cache it (normal insert):
{insert name="content" view="item"}
Show a content list and cache the output in the template (force caching):
{static name="content" view="list"}
This works as espected and accelerate my application. But in sometimes when
I use {static ...} and {insert ...} in an template, some insert-calls in
cached templates failed with (Output of Smarty.class.php,v 1.392):
Notice: Undefined index: content in d:\docroots\ectnd\sys\libs
\Smarty.class.php on line 1845
Fatal error: Call to undefined function: () in d:\docroots\ectnd\sys\libs
\Smarty.class.php on line 1846
This comes up in _process_cached_inserts() because there is no entry in
$this->_plugins['insert'] for the insert-plugin.
As workaround I include the plugin "manually":
if (isset($this->_plugins['insert'][$name])) {
// normal behavior
$function_name = $this->_plugins['insert'][$name][0];
} else {
// workaround
$function_name = 'smarty_insert_' . $name;
require_once MY_PLUGIN_DIR . 'insert.' . $name . '.php';
}
But I have no idea how to solve this correct..
Any other? :-)
Thomas.
--
http://4bconsult.de