{foreach}{/foreach}

Applies to: Jamroom 7.0+ Last verified: 2026-10-24
  • Looping over items

    {foreach} repeats part of a template for each element of an array. In Jamroom, lists made by {jrCore_list} give their template the items in $_items, and the list template loops over them:

    {if isset($_items)}
    {foreach $_items as $item}
        <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.audio_title_url}">{$item.audio_title}</a>
    {/foreach}
    {/if}
  • By convention, Jamroom names arrays with an underscore ($_items) and a single element without ($item).

  • What's in $item

    $item holds all of an item's fields: its title, files, owner, profile, created and updated times, counts, and more. Use any of them with a dot: {$item.audio_title}, {$item.profile_name}, {$item._created}.

    To see every field, add {debug} to the template, or look at the item in the module's DataStore Browser (the module's Tools tab).

  • More

    {foreachelse} shows something when the array is empty. {$item@iteration} is the loop count, starting at 1. Jamroom also adds list_rank, the item's position in the whole list across pages. See the Smarty foreach documentation.

Tags