SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smarty section problem

    Hi guys,

    I am trying to loop through the following array using smarty. However, it seems I have tried everything and cannot get smarty to loop through the multi dimensional array. Please help.

    Array:
    PHP Code:
    Array ( [relatedTerms] => Array ( [0] => Golf Holiday [1] => Golf [2] => Open Golf [3] => Golf Accessory [4] => Golf Course [5] => British Open [6] => British Open Golf [7] => Golf Lesson [8] => Master [9] => Tiger Woods ) [popularCategories] => Array ( [Football] => Array ( [0] => World Cup [1] => Football [2] => Football Game [3] => FIFA World Cup [4] => Match ) [Horse Racing] => Array ( [0] => Horse Racing Result [1] => Horse Racing Game [2] => Racing Result [3] => Equestrian [4] => Horse Racing Tip ) [Cricket] => Array ( [0] => Bet on Cricket [1] => Cricket Game [2] => Live Cricket [3] => Lord Cricket Ground [4] => Pakistan Cricket ) [Motor Racing] => Array ( [0] => Formula 1 [1] => Post Racing [2] => National [3] => Grattan [4] => Moto Gp ) [Rugby] => Array ( [0] => Jonny Wilkinson [1] => Canterbury Rugby [2] => Canterbury Rugby Shirt [3] => Heineken Cup [4] => Murrayfield ) [Tennis] => Array ( [0] => Wimbeldon [1] => Roland Garros [2] => Wimbledon Hospitality [3] => Wimbledon Championship [4] => Wimbledon Lawn Tennis ) )) 
    Smarty:
    Code PHP:
    {section name="i" loop=$links.popularCategories}
              {section name="x" loop=$links.popularCategories[i]}
                {$links.popularCategories[i][x]}
              {/section}
            {/section}

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not really too familiar with smarty, but I think you're supposed to be using {foreach}
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, managed to do it using {foreach}

  4. #4
    SitePoint Enthusiast O_o.moo's Avatar
    Join Date
    Aug 2007
    Location
    South Africa
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    New problem. I post here, because of foreach.

    My problem is that a friend of mine used a Smarty plugin, table_foreach (http://smarty.incutio.com/?page=table_foreach), but since one of our server upgrades it doesn't work anymore. Basically what it did was to build a table with the correct amount rows and columns.

    Does anyone know of any other idea or plugin? At the moment we are just using foreach but it doesn't have the desired layout effect. Lets say there's only three images for the entry it all aligns left instead of centering the 3.

    Even if someone's got a better CSS solution for the problem I'd be grateful.

    Example - http://www.jordanwines.com/wines/index.php?cid=1
    My Temporary Résumé!
    watch this space

  5. #5
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you guys still supporting smarty in the world of MVC. native templating is faster and easier than any third party templating engines.

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Smarty fits into MVC...

    The loss of speed with Smarty is negligible (Smarty executes one-time-generated native PHP code), so it's only a matter of preference (of syntax). Every other point is moot.

    (Really, there is no argument. It's only a matter of preference. You can look up rants against Smarty written by a lot of people, but they have hardly used it. They are flat out wrong. Someone on here purported that they had used Smarty for years; however, he did not even know that Smarty used caching and so argued that there was a major performance hit. You can't even use Smarty without setting up a cache directory!)

    *By cache, I mean the one-time-generated versions for the template files. Smarty has a separate optional cache that caches the content of select pages to increase performance.

  7. #7
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just look at the syntax posted in the original post... I thought the whole point was to separate logic from the HTML, but I can see 2 loops, and no HTML at all! Smarty has got a bit too complicated for its own good I think.

    I'm working on my own templating system at the moment, just as a test, it's quite interesting, but unsure if i'll use it all the time.

  8. #8
    SitePoint Enthusiast O_o.moo's Avatar
    Join Date
    Aug 2007
    Location
    South Africa
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by O_o.moo View Post
    Hi,

    New problem. I post here, because of foreach.

    ...
    Creating a new post...
    My Temporary Résumé!
    watch this space

  9. #9
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    can anyone help me for this issue

    I am worked on CakePHP which is MVC architecture but, now i want to implement in smarty php.please give any example code for this issue, i spent more and more time for searching in it.

    Thanks In Advance

    Anil Kumar

  10. #10
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For gosh sakes, why can't someone ask a question about smarty or any templating engine without getting an objection or lecture about using template engines.

    Seems like it happens every time.


Bookmarks

Posting Permissions

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