1.11.9

News

Jan 3, 2014
Category: General
Posted by: admin
The news module was installed. Exciting. This news article is not using the Summary field and therefore there is no link to read more. But you can click on the news heading to read only this article.
CMS - 1.11.9 - Bartolome
 

Using Smarty Foreach Loops

Grab a random result from a foreach loop by doing something like this:

{assign var=randomindex value=$items|@array_rand} {foreach from=$items item=item} {if $item == $items.$randomindex} {$item->title} {/if} {/foreach}


This will print a random module name from a list of module names from this Indexed array:

Indexed Array List: News, Search, MicroTiny, Menu Manager
Random Result: News

This will print a random module name from a list of module names from this Associative array:

Associative Array List: News: 2.14.1, Search: 1.7.11, MicroTiny: 1.2.5, Menu Manager: 1.5.5
Random Result: MicroTiny: 1.2.5

This will print a random module name from a list of module names from this multidimensional array:

Multidimensional Array List:
Core Modules: News, Search, MicroTiny, Menu Manager
Addon Modules: Gallery, TinyMCE, CGCalendar, ListIt2
Random Result:
Addon Modules: Gallery, TinyMCE, CGCalendar, ListIt2

Split a foreach loop in half to make two columns

{assign var='listsum' value=$items|@count}
{math equation="x * y" x=$listsum y=.5 assign='itemscol'}
< ul>
{foreach $items as $item}
{if $itemscol is odd}{assign var=itemscol value=$itemscol+1}{/if}
{if $item@iteration <= $itemscol|@floor}
< li>{$item->title}< /li>
{/if}
{/foreach}
< /ul>
< ul>
{foreach $items as $item}
{if $item@iteration > $itemscol|@floor}
< li>{$item->title}< /li>
{/if}
{/foreach}
< /ul>

Example output

  • Item One
  • Item Two
  • Item Three
  • Item Four
  • Item Five
  • Item Six
  • Item Seven

Previous page: Mobile Device Detection  Next page: Resources