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

Smarty foreach index does not act on second item in the list

 
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
Saeid
Smarty Rookie


Joined: 21 Jun 2010
Posts: 25

PostPosted: Fri Mar 14, 2014 12:59 pm    Post subject: Smarty foreach index does not act on second item in the list Reply with quote

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
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Mar 14, 2014 4:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
Saeid
Smarty Rookie


Joined: 21 Jun 2010
Posts: 25

PostPosted: Mon Mar 17, 2014 3:50 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
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