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

xen foreach

Discussion in 'XenForo Development Discussions' started by DroidHost, Jun 23, 2011.

  1. DroidHost

    DroidHost Well-Known Member

    I want to use foreach statment but my mind is locked for now
    so I want some help here

    I have an array
    I want the template to enter a loop and fill the variable with diff value
    Somethins like
    PHP:
    array (data=>array( 'names' => array('ali ','james')))
    ___
    in the template if I am correct which I don't

    Code:
    <xen:foreach loop="$names"    value="$name">
    
            {$name}
    
    </xen:foreach>
     
  2. Marc

    Marc Well-Known Member

    Depending on what you have sent to the template would it not be something like the following:

    Code:
    <xen:foreach loop="$names"    value="$name">
    {$name.name}
    </xen:foreach>
    
    Would need to see what your actually sending to the template

    EDIT: Ignore that, didnt read your post properly LOL
     
  3. Marc

    Marc Well-Known Member

    Could be way off the mark here .. but would you not be looping through $data.names?
     
  4. DroidHost

    DroidHost Well-Known Member

    PHP:
                <xen:foreach loop="$data"    value="$data">
                    <
    class="externalLink" rel="nofollow" target="_blank" href="{$data.url}"><img src="{$data.img}alt="" title="{$data.caption}/></a>
                  </
    xen:foreach>
    I dont know ... maybe if I used it in PHP code level .. will solve this issue
    I will think of something !
     
  5. DroidHost

    DroidHost Well-Known Member

  6. Korenwolf

    Korenwolf New Member

    and the solutions is ?
     
  7. DroidHost

    DroidHost Well-Known Member

    the array :
    PHP:
            $data = array(
            
    'bannars'=>array(
                
    '1'=>
                array(
                 .........
                ),
                
    '2'=>
                array(
                 .........
                ),
                
    '3'=>
                array(
                 .........
                ),
                
    '4'=>
                array(
                ........
                ),
                
    '5'=>
                array(
                 ...
                ),
            ));
    then send $data ...

    after that in the template it will work !
    HTML:
                <xen:foreach loop="$data"    value="$data">
                    <a class="externalLink" rel="nofollow" target="_blank" href="{$data.url}"><img src="{$data.img}" alt="" title="{$data.caption}" /></a>
                  </xen:foreach> 
     

Share This Page