Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Bug with the variable names of parameters in conf files

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
localghost
Smarty n00b


Joined: 02 Jun 2004
Posts: 2

PostPosted: Wed Jun 02, 2004 1:38 pm    Post subject: Bug with the variable names of parameters in conf files Reply with quote

It is not possible to use config parameters dynamically:
If you load a config file and then use some of the config parameters it is ok, but when you try to use config parameter as variable the parameter does not show.

Here is an example:
WORKING:
{config_load file="setup.conf"}
{#foobar#}

NOT WORKING:
{config_load file="setup.conf"}
{assign var="varname" value="foobar"}
{#$varname#}

Please advise...

Respect for the really SMARTY template engine Smile
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jun 02, 2004 2:03 pm    Post subject: Reply with quote

That's not a bug, of course, that's a feature Smile Seriously, config files were never designed for that but instead are a means to introduce static text into your templates (=fast) and that is all.

If you want to use them as vars, you have to do a little more work, for example using {capture} which I won't describe since it is an awkward solution, IMO.

Much better is if you use an array to store the vars you want to handle dynamically:
Code:
{assign var=temp value=#foobar#}
{$myarr.$temp}


Even here, you are forced to use an ugly temp var. Conversely, you can do something like this:

Code:
{$myarr[$smarty.config.foobar]}


But that's about as good as it gets, AFAIK.

Note, it is a fairly common practice to submit all your vars to a template in a single "payload" style array.
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jun 02, 2004 2:07 pm    Post subject: Reply with quote

{#$varname#} doesn't work. {$smarty.config.$varname} does.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
localghost
Smarty n00b


Joined: 02 Jun 2004
Posts: 2

PostPosted: Thu Jun 03, 2004 7:31 am    Post subject: Reply with quote

Thank you both for the very useful information you shared with me, I really should learn to read the Smarty Manual in details.

Anyway thank you very much Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP