We have a social network startup and we need to integrate smarty templates. I have a php array namely $profile_tasks . An element in $profile_tasks have the following properties ;
[0] => Array
(
[name] => hello
[location] =>
[date] =>
[time3] => 0
[time1] =>
[state] => 0
[like_count] => 0
[comment_count] => 2
[does_id] => 91
[comments] => Array
(
[sender_id] => 27
[content] => khhkhjkkhk
[time] => 2012-02-09 20:06:13
[user_name] => aacanakin
[picture_url] => http://graph.facebook.com/fb_user_name/picture
)
)
In my smarty template file, I have assigned the $profile_tasks array like this ;
$smarty->assign("profile_tasks", $profile_tasks);
In my .tpl file, there is no problem in printing any of the attributes like [name] or [location] fields. I have the following code for name printing ;
{foreach name=outer item=profile_task from=$profile_tasks}
{$profile_task.name}
{$profile_task.locatin} // these two works correctly
{foreach name=inner item=comment from=$profile_task.comments}
{comment.user_name} // these three statements doesn't return correct values
{comment.picture_url}
{comment.content}
{/foreach}
{/foreach}
So, as I stated before, the values inside comments array are not correct. What should I change in the inner loop ? Any help will be appreciated.
Just use
you dont need
if your comments array had multiple sub arrays then you would.
UPDATE:
Update based on comment. Your array needs to look like this for your origional code to work
PS. On a subnote, I very early on realised that using the default
{}to denote smarty tags is really annoying as you cannot happily co-exist with javascript on a html template page. If you havn’t gone too far down the route I would useto specify an alternative. This means you dont have to worry about using the {literal} tags anywhere.