Skip to content

Instantly share code, notes, and snippets.

@makbeta
Created November 30, 2012 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save makbeta/4173330 to your computer and use it in GitHub Desktop.
Save makbeta/4173330 to your computer and use it in GitHub Desktop.
Luminate CMS: Display 3 random items from the list
<t:if test="length > 0"><!-- is there a list? -->
<t:set id="iRandom" value="random(length)+1" /><!-- set a variable equal to a number between 1 and the length of the list -->
<!-- if random number is within 2 of the last item in the list, subtract 2 -->
<t:if test="iRandom >= (length-2) && iRandom <= length">
<t:set id="iRandom" value="iRandom-2" />
</t:if>
<!-- if the variable is now negative due to the subtraction above, reset it to 1 (the first list item) -->
<t:if test="iRandom <= 0">
<t:set id="iRandom" value="1" />
</t:if>
<!-- simple 3-column table output open the table and tr outside of the list -->
<table width="100%" cellspacing="5">
<tbody>
<tr>
<t:list><!-- start looping through the list -->
<t:if test="index == iRandom || index == (iRandom+1) || index == (iRandom+2) "><!--if the list index position matches our variable, start the output-->
<td valign=top width="33%">
<strong>${title}</strong><br>
${description}<br>
<a href="${external_url}">More Information</a>
</td>
</t:if>
</t:list>
</tr>
</tobdy>
</table>
</t:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment