Reputation: 10061
I am fetching an array and I would like to assign attributes of items within the array to individual variables. For example, I want to assign a variable named user_1_name to include userInfo.name from the first userID and user_2_name to include userInfo.name from the second userID. Here is the code as it stands now, it uses a proprietary method named 'get_friend_list':
{assign var="friend_list" value=""}
{get_friend_list snid=$TOSNID snuid=$TOUID gameid=$GAMEID assign="friend_list"}
{if $friend_list|@count > 0}
{foreach from=$friend_list key=userId item=userInfo name=friend_list}
{if $smarty.foreach.friend_list.index < 4 && $smarty.foreach.friend_list.index >= 0 && !empty($userInfo.user_uid) }
***VARIABLE ASSIGNMENT HERE***
{/if}
{/foreach}
{else}
{/if}
If this is an unclear question, let me know and I will attempt to clear it up.
Thanks
EDIT: BTW, if you didn't notice, I am using Smarty.
Upvotes: 3
Views: 1166
Reputation: 23001
Did you try:
{assign var="user_{$smarty.foreach.friend_list.index}_name" value=$userInfo.name}
?
Upvotes: 2