Re: [SMARTY] Problem with ConfigFiles (scope global)

From: Date: Thu, 16 May 2002 22:20:56 +0000
Subject: Re: [SMARTY] Problem with ConfigFiles (scope global)
References: 1 2 3 4 5 6 7 8  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4254@lists.php.net to get a copy of this message
I think I see what you are trying to do. But, I don't think Smarty config files work the way you want them to. For one, scope=global just means that parent templates (templates that included the current template) will have access to the loaded variables. It will not accomplish anything with doing a fetch() inside of an insert statement. If you do something like this: $smarty->display('index.tpl'); $smarty->display('foo.tpl'); and you load config file variables in index.tpl, the variables will NOT be available to foo.tpl when it gets displayed. config_file variables are only available within the display() or fetch() call they are used. I'm not sure if this would be considerd a bug or not, since I doubt anyone has tried this before ;-) Maybe an alternate way to get what you want is to load the config file vars manually and assign them using the Config_File class directly. $conf = new Config_File('./configs'); // load globals $smarty->assign($conf->get('foo.conf')); // load one section $smarty->assign($conf->get('foo.conf','mysection')); // load one var, section can be null for global var $smarty->assign($conf->get('foo.conf','mysection','myvar')); $smarty->display('index.tpl); You will access config vars as $foo instead of #foo# by assigning them this way. See if the assigned variables are still available from within the fetch call. Monte Norbert Röcher wrote:
"Monte Ohrt" <monte@ispi.net> schrieb:
Sorry to hear that. I just don't understand what you're trying to accomplish or exactly how things are setup. Maybe an explicit
example of
scripts/templates to demonstrate the problem would help.
I just tried to include fetched templates by {insert}. That's all, in fact. The problem is, that config_vars with scope "global" were only available in the main template und not available while fetching the sub-templates within my insert-function - using the same smarty-object, while this object definetly contains all necessary data. To me this seems to be a bug in smarty. Simplified code: _____________________________________ PHP_APPLICATION: $smarty->assign(id, $id); $smarty->display('index.tpl'); INDEX.TPL: {config_load file="styles.conf" scope=global} {insert name=block id=$id} STYLES.CONF: color1=00000 color2=FFFFF SMARTY_INSERT_BLOCK.PHP: function smarty_insert_block ($params, &$smarty) {
    $data = getBlockDataByID($params['id']);
    $smarty->assign('content', $data['content']);
    return $smarty->fetch($data['subtemplate']);
} SUBTEMPLATE.TPL: {#color1#} {*should contain value from style.conf, but doesn't*} {#color2#} {*should contain value from style.conf, but doesn't*} _____________________________________ Regards, Norbert
-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.

« previous php.smarty.general (#4254) next »