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

Dynamic config variables? (like {#color{$colorname}#}??

 
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 -> General
View previous topic :: View next topic  
Author Message
tdm
Smarty Rookie


Joined: 01 May 2003
Posts: 18

PostPosted: Mon Aug 18, 2003 5:38 pm    Post subject: Dynamic config variables? (like {#color{$colorname}#}?? Reply with quote

I have some colors set in my config file, named like 'color[groupname]' where [groupname] could be 'home', 'esta', 'scout', 'explo'.

{note: This is about a news page}

Every news message contains one field which tells me for which group the message is. So I did this in my template:
Code:
{section name='newslist' loop=$results}
  <tr bgcolor="{#color{$result[newslist].sidname}#}">
    <td class="adminNewsOverviewTitleRowCell">{html_link page="nieuws.php" nid=$results[newslist].nid title=$results[newslist].title text=$results[newslist].title|truncate:30}</a></td>
    <td class="adminNewsOverviewSpeltakRowCell">{$results[newslist].sidname}</td>
    <td class="adminNewsOverviewDateRowCell">{$results[newslist].postdate|date_format:"%a %d-%m-%Y %H:%M"|capitalize}</td>
    <td class="adminNewsOverviewFunctionsRowCell">[ <a href="#">{#adminNewsOverview_functionEdit#}</a> | <a href="#">{#adminNewsOverview_functionDelete#}</a> ]</td>
  </tr>
{/section}

To make clear about which part I'm talking about:
Code:
{section name='newslist' loop=$results}
  <tr bgcolor="{#color{$result[newslist].sidname}#}">


This gives me an error like:
Code:
Fatal error: Smarty: [in admin/admin_nieuws_overview.tpl.html line 46]: syntax error: unrecognized tag: #color{$result[newslist].sidname (Smarty_Compiler.class.php, line 410) in /home/httpd/htdocs/ascanenv2.nl/includes/Smarty/Smarty_Compiler.class.php on line 2040


How can I do this right, so it gives the output of the 'color[groupname]' constant like I have set it in my config file?

Thanks
Back to top
View user's profile Send private message
CirTap
Smarty Pro


Joined: 04 Jun 2003
Posts: 106

PostPosted: Mon Aug 18, 2003 6:12 pm    Post subject: Reply with quote

Re,
I think you have to use backticks for this, but I never tried to create variable variable-names with Smarty Smile
Code:
<tr bgcolor="{#color`$result[newslist].sidname`#}">

http://smarty.php.net/manual/en/language.syntax.quotes.php

If this does not work, load the Config-File in PHP and add the color as a new key to the $result array. This is probably less trouble and you can stoll use the config files to change the colors.
See this thread about reading config files in PHP.

Have fun,
CirTap
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 -> General 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