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

Access to the two-dimensional array in the template

Discussion in 'XenForo Development Discussions' started by Hugilore111, Apr 8, 2016.

  1. Hugilore111

    Hugilore111 Member

    Hello!
    I have a two-dimensional array
    Code:
    Array
    (
        [0] => Array
            (
                [enter_id] => 1
                [user_id] => 1
                .....
    )
    [1] => Array
            (
                [enter_id] => 2
                [user_id] => 1
                .....
           )
    )
    
    How to walk in a series of two-dimensional array in a template?
    I'm trying to do
    Code:
    <xen:foreach loop="$entr" key="$key" value="$val" >
        {xen:raw $val.messageHtml}
    </xen:foreach>
    
    I get template empty array
    Array()
     
    Last edited: Apr 8, 2016
  2. Snog

    Snog Well-Known Member

    Be sure you pass $entr from your PHP to the template.

    Then it's...
    Code:
    <xen:foreach loop="$entr" value="$entrvalue">
       {xen:raw $entrvalue.messageHtml}
    </xen:foreach>
    
     
  3. Hugilore111

    Hugilore111 Member

    Hi Snog
    yes comes array
    shows in template Array Array
     
  4. Snog

    Snog Well-Known Member

    There is something wrong with your array then. I tested this by creating an array in PHP and passing it to a template..
    Code:
    $entr = array(array('a' => 'This is a', 'b' => 'This is b'),array('a' => 'This is 1c', 'b' => 'This is 1d'));
    
    And put this code in the template (your original code)...
    HTML:
    {xen:helper dump,$entr}
    <br />
    <xen:foreach loop="$entr" key="$key" value="$entrvalue">
       {xen:helper dump,$entrvalue}
       {xen:raw $entrvalue.a}
       <br /><br />
    </xen:foreach>
    
    And the results printed without a problem...
    Code:
    array(2) {
      [0] => array(2) {
        ["a"] => string(9) "This is a"
        ["b"] => string(9) "This is b"
      }
      [1] => array(2) {
        ["a"] => string(10) "This is 1c"
        ["b"] => string(10) "This is 1d"
      }
    }
    
    
    array(2) {
      ["a"] => string(9) "This is a"
      ["b"] => string(9) "This is b"
    }
    
    This is a 
    
    array(2) {
      ["a"] => string(10) "This is 1c"
      ["b"] => string(10) "This is 1d"
    }
    
    This is 1c
    
     
    Hugilore111 likes this.

Share This Page