I have the following smarty structure (I’ve removed the unnecessary checks and visualisations):
[4] {$vip_comments = array()}
{foreach from=$comments item=comment}
{include file="layouts/comments_deepscan.htm" show_only=$comment.id vip_id=$comment.id}
{/foreach}
[3] {$vip_comments|print_r:true}
The comments_deepscan structure looks like this (I’ve removed the unnecessary checks and visualisations):
{foreach from=$comments item=comment}
{if $comment.access_level == 5}
[1] {$vip_comments[$vip_id] = true}
[2] {$vip_comments|print_r:true}
{break}
{/if}
{include file="layouts/comments_deepscan.htm" show_only=$comment.id vip_id=$vip_id}
{/foreach}
In some examples the [1] and [2] rows have been called, so $vip_comments looks like this:
Array ( [10446] => 1 )
However when the loops finish row [3] gives me an empty array. I think, that $vip_comments is not visible inside the deep scan loops, so it creates a new empty array and pushes the data inside.
I have tried to pass it as a reference like this (but it does not work):
{include file="layouts/comments_deepscan.htm" show_only=$comment.id vip_id=$comment.id vip_comments=&$vip_comments}
How to push elements inside the $vip_comments array on row [4]?
You don’t say wich smarty version are you using, For smarty 3, try changing the scope of the included templates with “scope”
I will also take a look at {function}: http://www.smarty.net/docs/en/language.function.function.tpl, wich is a much better solution to what you’re trying to do.
If you’re using smarty 2, I don’t think it can be done.
However, note that smarty is a presentation oriented template system, and that (even if it can be done) it’s faster and preferable to do all this logic operations of processing data and creating arrays out of it in php.