• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Need help with $viewParams and xen:foreach loop

AndyB

Well-known member
#1
I'm creating an add-on which will display a row of links. My PHP file runs a query and returns an array called $post_id which contain post numbers.

What I would like to know is how to pass the $post_id array to my template so that each post number in the $post_id will be displayed.

My PHP:

PHP:
$viewParams = $post_id; // this does not work

return $this->responseView('Andy_ShowDeleted_ViewPublic_ShowDeleted', 'andy_showdeleted', $viewParams);
The andy_showdeleted template:

Code:
<xen:foreach loop="$post_id" value="$post_id">
   {$post_id}
</xen:foreach>
 
Last edited:

Mythotical

Well-known member
#2
You want to use this:

PHP:
    $viewParams = array(
       'post_id' => $post_id
     );
HTML:
<xen:foreach loop="$post_id" value="$pId">
{$pId}
</xen:foreach>
 

AndyB

Well-known member
#3
That works perfect. Thank you, Mythotical.

Now I'm going to try and add $thread_id to the PHP and display that too.
 

AndyB

Well-known member
#5
Adding $thread_id was easy.

PHP:
    $viewParams = array(
       'post_id' => $post_id,
       'thread_id' => $thread_id,
     );
     
     return $this->responseView('Andy_ShowDeleted_ViewPublic_ShowDeleted', 'andy_showdeleted', $viewParams);
Code:
<xen:foreach loop="$post_id" value="$pId">
{$pId}<br />
</xen:foreach>

<xen:foreach loop="$thread_id" value="$pId">
{$pId}<br />
</xen:foreach>