{foreach}{/foreach}

  • Overview

    The {foreach} loop is a method for iterating over an array of objects.

    The official Smarty Docs for the {foreach}{/foreach} loop are here.
  • Looping over $_items

    In Jamroom, its a common convention to name arrays with an underscore $_items will almost always be an array containing many items, while $item will an individual item.
    The function used to retrieve a list of items is the {jrCore_list} function.
    The most common {foreach} loop you will see is in the item_list.tpl files of modules, it will look like this:

    {foreach $_items as $item}
      // some formatting for the list for each item
    
    {/foreach}
  • Contents of $item

    The contents of $item is all the data related to that particular item, so if its an audio item, there will be the name of the item, the title, the file associated with it, the owner, which profile its on, when it was created, when it was updated.......... and a lot more info.

  • screenshot of the {debug} panel with an audio item highlighted
  • Inside the {foreach} loop, you can access any of the item values by asking for it by its key:
    {$item.audio_title}
    would give you green trees

    {$item.audio_album}
    would give you all along the wall

    etc...
  • Take a look at the {debug} docs for more details on debug.

Tags