|
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 |
localghost Smarty n00b
Joined: 02 Jun 2004 Posts: 2
|
Posted: Wed Jun 02, 2004 1:38 pm Post subject: Bug with the variable names of parameters in conf files |
|
|
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 |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jun 02, 2004 2:03 pm Post subject: |
|
|
That's not a bug, of course, that's a feature 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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jun 02, 2004 2:07 pm Post subject: |
|
|
{#$varname#} doesn't work. {$smarty.config.$varname} does. |
|
Back to top |
|
localghost Smarty n00b
Joined: 02 Jun 2004 Posts: 2
|
Posted: Thu Jun 03, 2004 7:31 am Post subject: |
|
|
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 |
|
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
|