|
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 |
Saeid Smarty Rookie
Joined: 21 Jun 2010 Posts: 25
|
Posted: Fri Mar 14, 2014 12:59 pm Post subject: Smarty foreach index does not act on second item in the list |
|
|
Hi all, I am not sure if I am doing something wrong or this is an bug. This is the case:
I have a conf file with following content:
Code: |
[roles]
role = Scientific staff
role = Secretary
role = PostDocs
role = Ph.D. students
role = Supporting staff
role = PNUT
role = Visitors
role = Internship
[colors]
color = white
color = red
color = green
color = red
color = blue
color = brown
color = yellow
color = cyan
|
So I want to simply output each role with its respective color to the screen, here is my tpl file:
Code: |
{config_load file="members.conf" section="roles"}
{config_load file="members.conf" section="colors"}
{* header and stuff... *}
<div class="members"> {* MEMBERS *}
{foreach from=#role# item=r name=roles}
<span style="color: {#color#[$smarty.foreach.roles.index]}">{$r}</span>
{/foreach}
</div> {* MEMBERS *}
|
The problem is, for the second item (in this case its 'Secretary') there will be no color!! it always shows black....while the other colors work just fine. Can you please tell me what I am doing wrong? Also, is there any better way to achive similar result? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 14, 2014 4:00 pm Post subject: |
|
|
I can't reproduce the problem. It's working just fine at myplace.
Perhaps you have some invisable character in your config file.
Reenter the color = Red line.
With $smarty->debugging = true; you can check the loaded values |
|
Back to top |
|
Saeid Smarty Rookie
Joined: 21 Jun 2010 Posts: 25
|
Posted: Mon Mar 17, 2014 3:50 pm Post subject: |
|
|
Hi, Thanks for reply. You were right....aparently I had hardcoded those values in my php file. It works fine now!
But can you tell me if the way that I am doing this is efficent or you have a better idea? |
|
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
|