|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
tdm Smarty Rookie
Joined: 01 May 2003 Posts: 18
|
Posted: Sat May 03, 2003 11:20 am Post subject: [Modifier Plugin] Reading result from array? |
|
|
I want to have a modifier which results a value from an array.
This is what I got now, and I don't see anything wrong.
What's wrong?
Code: |
function smarty_modifier_get_config_value($string, $section, $confvar = 'conf')
{
GLOBAL ${confvar};
return ${confvar}[$section][$string];
}
|
The file containing this modifier is called "modifier.get_config_value.php", and it remains inside the 'plugin' dir I specified with Smarty. So that couldn't be the problem.
But I won't get any result from it
I get an output when I insert in the modifier, but I can't get anything from the array
I include my config file into the Php file which calls the template using this modifier, the config file containing the array looks like this:
Code: | <?php
$conf['bgcolor']['esta'] = "#00CC00";
$conf['bgcolor']['scout'] = "#FFB76F";
$conf['bgcolor']['explo'] = "#FF0000";
$conf['bgcolor']['home'] = "#99CC99";
$conf['text_bgcolor']['esta'] = "#00CC00";
$conf['text_bgcolor']['scout'] = "#FFB76F";
$conf['text_bgcolor']['explo'] = "#FF8989";
$conf['text_bgcolor']['home'] = "#99CC99";
?>
|
Any idea what I'm doing wrong, or how I could get this working?
Thanks |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat May 03, 2003 11:26 am Post subject: |
|
|
Try $$confvar instead of ${confvar}.
By the way, you might want to consider alternative approaches of storing your required data. Perhaps create a single known global var to store an array of data items.
ie. GLOBAL $mystorage |
|
Back to top |
|
tdm Smarty Rookie
Joined: 01 May 2003 Posts: 18
|
Posted: Sat May 03, 2003 11:32 am Post subject: |
|
|
boots wrote: | Try $$confvar instead of ${confvar}.
By the way, you might want to consider alternative approaches of storing your required data. Perhaps create a single known global var to store an array of data items.
ie. GLOBAL $mystorage |
$$confvar doesn't do much
What do you mean with the alternative approaches of storing required data?
Don't I have one global var containing the array of data items? ($conf, but to make it dynamic I want to be able to give also a different $confvar)
Could you explain some more?
Thanks |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat May 03, 2003 11:54 am Post subject: |
|
|
I meant that if you did something like this:
Code: | function smarty_modifier_get_config_value($string, $section, $confvar = 'conf')
{
GLOBAL $confvars;
return $confvars[$confvar][$section][$string];
} |
The thing is, is that you don't want to "pollute" your global namespace with too many vars.
You can also extend smarty and store the array there:
Code: | class MySmarty extends Smarty
{
var $confvars;
}
$smarty = new MySmarty; |
Your modifier would then be something like:
Code: | function smarty_modifier_get_config_value($string, $section, $confvar = 'conf')
{
return $this->confvars[$confvar][$section][$string];
} |
I hope that is clearer.
Still, I'm not sure why you are going through these hassles for conf values which are usable directly from within templates via ##.
Last edited by boots on Sat May 03, 2003 12:18 pm; edited 1 time in total |
|
Back to top |
|
tdm Smarty Rookie
Joined: 01 May 2003 Posts: 18
|
Posted: Sat May 03, 2003 12:02 pm Post subject: |
|
|
boots wrote: |
I hope that is clearer. |
Getting there
boots wrote: |
Still, I'm not sure why you are going through these hassles for conf values which are usable directly from within templates via ##. |
I need the flexibility to change the values of the config files from a webpage, and with the pear::Configuration class it's easy.
I don't know if the pear::Configuration class' inifile-type has the same layout as the Smarty Config file layout?
And most important, I need to get the value of the config file dynamicly.
The result of a query from the DB has a field which contains the name of a section (it's a site for a scouting group, and the group is splitted in differents groups selected by the age of the members), and I want every group to have a different layout color. So I want to use the groupname to get the right color from a config file.
( I hope I made clear 'why' I want this ) |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|