Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Loop to smarty

  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Loop to smarty

    Hello

    I know Little about Smarty i know how to assign Easy Vairble to Smarty like

    PHP Code:
    echo $image 
    to

    PHP Code:
    $smarty->assign('image'$image); 
    But how i assign Loop .. this Code Below add Image For each 1 , if image equal 1 then add one image if image 2 add two images .. but i do not know how to assign it with smarty.

    PHP Code:
    for($i=1;$i<=$image$i++){ 
    echo 
    '<img src="/images/star.png" />'

    i tried to do it like this

    PHP Code:
    for($i=1;$i<=$image$i++){
     
    $smarty->assign('image''<img src="/images/star.png" alt="" />');

    but it only prints out one image .. regrads wht $image equals
    Last edited by ajloun; 02-20-2010 at 12:53 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Solved it ..

    PHP Code:
    $total =2;  
    $image ''
    for(
    $i=1;$i<=$total$i++){  

    $image .= '<img src="'.PATH.'/images/star.png" />';  


    $smarty->assign('image'$image); 

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    It would make more sense to assign the number of stars to a variable in smarty then use a for loop in smarty

    In your php:
    PHP Code:
    $smarty->assign('maxloop'$total); 
    Then in your template use
    Code:
    {section name=loop start=1 max=$maxloop}
    <img src="'.{$smarty.const.PATH}.'/images/star.png" />
    {/section}
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •