1. 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

Discussion in 'XenForo Development Discussions' started by AndyB, Sep 27, 2013.

  1. AndyB

    AndyB Well-Known Member

    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: Sep 27, 2013
  2. Mythotical

    Mythotical Well-Known Member

    You want to use this:

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

    AndyB Well-Known Member

    That works perfect. Thank you, Mythotical.

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

    Mythotical Well-Known Member

    Yw, good luck.
     
  5. AndyB

    AndyB Well-Known Member

    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>
    
     

Share This Page