View previous topic :: View next topic |
Author |
Message |
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Thu May 27, 2004 4:35 pm Post subject: Variable in variable from config-file |
|
|
Hi,
i hope, that it isnt already posted somewhere here and that not too many found it out already
I wrote in the config-file this
icon_0 = /images/icon0.gif
icon_1 = /images/icon1.gif
and so on
and in my mysql_db "topic_icon" should be a number (i.e. 0 or 1)
So it should display "/images/icon0.gif" when in db topic_icon=0
in the template:
Code: |
{config_load file=d1.conf section=topic_icons"}
{assign var="icon_number" value=$topics[idx].topic_icon}
{assign var="vari" value="icon_$icon_number"}
<img src="{$smarty.config.$vari}"></td>
|
is there a better way to do this?
if so, i didnt found it... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 27, 2004 4:40 pm Post subject: |
|
|
If all your icons are named that way, do you really need a config file?
<img src="/images/icon{$topics[idx].topic_icon}.gif"> |
|
Back to top |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Thu May 27, 2004 5:36 pm Post subject: |
|
|
sure, if sbd decides, the icons should be named like
aicon.gif
bicon.gif
and so on...it should all be variable |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu May 27, 2004 5:58 pm Post subject: |
|
|
you can set $smarty->config_overwrite to false
then in your config-file
Code: |
icon = /images/icon0.gif
icon = /images/icon1.gif
|
gives you an array. you can access that via {$smarty.config.icon.$i} |
|
Back to top |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Thu May 27, 2004 8:08 pm Post subject: |
|
|
uhm...i didnt see that
ok...and is there a way to loop and display them?
(I actually do with a ini-function in php but when i set "icon" instead of "icon_0" i cant read the values) |
|
Back to top |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Thu May 27, 2004 8:25 pm Post subject: |
|
|
in php
$smarty -> config_overwrite = false;
in html
{assign var="icon_number" value=$topics[idx].topic_icon}
{$smarty.config.icon.$icon_number}
returns:
Fatal error: Smarty: [in templates/d1/index.tpl line 73]: syntax error: $smarty.config.icon.$icon_number is an invalid reference (Smarty_Compiler.class.php, line 1969) in /var/www/html/libs/Smarty_Compiler.class.php on line 2062
did i do sth wrong? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu May 27, 2004 8:34 pm Post subject: |
|
|
upgrade to Smarty-2.6.2 (the latest stable) |
|
Back to top |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Thu May 27, 2004 8:38 pm Post subject: |
|
|
whew, fast answers here, respect
ill do so, and post the results...
but...how to do a loop through the icons to display them? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu May 27, 2004 8:42 pm Post subject: |
|
|
since $smarty.config.icon is an array
{foreach from=$smarty.config.icon item=icon} ...use $icon... {/foreach}
should do |
|
Back to top |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Thu May 27, 2004 8:47 pm Post subject: |
|
|
thx
so u can delete this topic...its outdated |
|
Back to top |
|
webadept Smarty Regular
Joined: 09 Mar 2004 Posts: 41
|
Posted: Sat Jun 12, 2004 2:48 am Post subject: |
|
|
This thread just saved me so many hours in so many ways I can't thank you enoough, for the questions and the answers. Just gets better all the time don't it? |
|
Back to top |
|
|