3

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.

1
  • please show the before and after array. Commented Mar 27, 2012 at 19:20

2 Answers 2

2

Did you try:

{assign var="user_{$smarty.foreach.friend_list.index}_name" value=$userInfo.name}

?

Sign up to request clarification or add additional context in comments.

Comments

0

Is that what you want? assign

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.