|
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 |
coolriree5 Smarty Rookie
Joined: 25 Jun 2009 Posts: 7
|
Posted: Fri Jun 26, 2009 8:12 am Post subject: array only printing the first letter of the value |
|
|
hello my array is only printing out the first letter from the value.
this is my array
Code: |
Array ( [posts] => Array ( [collar] => 56856877 [password] => ) [microsite] => Array ( [id] => [wdtsiteloggedin] => 1 [collar] => [email] => [firstname] => [lastname] => [rank] => ) [form_errors] => Array ( [0] => Array ( [errordiv] => collar_error [errormessage] => Please enter a valid collar number ) [1] => Array ( [errordiv] => password_error [errormessage] => Please ensure the field is filled out correctly ) ) )
|
this is my smarty loop
Code: |
{foreach from=$smarty.session.form_errors item=error}
{foreach from=$error item=item key=key}
{$item.errordiv}
{if $item eq "collar_error"}
{*<li>{$item}</li>*}
{/if}
{/foreach}
{/foreach}
|
and my result is
c P p P
however if i print out the item i get both the keys and the values
any suggestions of where i am going wrong in the loop?
thanks for the help in advance |
|
Back to top |
|
coolriree5 Smarty Rookie
Joined: 25 Jun 2009 Posts: 7
|
Posted: Mon Jun 29, 2009 9:03 am Post subject: |
|
|
RESOLVED
Code: |
{foreach from=$smarty.session.form_errors item=item key=key}
{if $item.errordiv eq "password_error"}
{$item.errormessage}
{/if}
{/foreach}
|
hello for those interested when using the $item.property method of looping, if you try to access the property too deep into the foreach (meaning you are using too many foreach loops) you will be returned with the first letter of each item
Thanks for all that looked at this
Nicholas
[/u] |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jan 13, 2010 8:17 pm Post subject: |
|
|
If you are only getting the first character you are accessing a string and not an array.
The reason "because it's nested too deep" is wrong here.
You should have used $error.errordiv and not $item.errordiv and you would only needed one foreach and not two nested ones. |
|
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
|