Skip to content

Instantly share code, notes, and snippets.

@jaygilmore
Last active December 10, 2015 21:08
Show Gist options
  • Save jaygilmore/4492603 to your computer and use it in GitHub Desktop.
Save jaygilmore/4492603 to your computer and use it in GitHub Desktop.
A MODX Revolution Version of Sal Sodano's RandomChunk to randomly display Chunks. Ideally used with Jason Coward's getCache.
<?php
/*
* RandomChunk
* Salvatore Sodano
* http://salscode.com
* Revolution Version 2013, Jay Gilmore aka smashingred
* [[!RandomChunk? &chunks=`chunk1, chunk2`]]
* Randomly generates a chunk from a comma separated list of chunks.
*
*/
$chunks = str_ireplace(" ","",$chunks);
$charray = explode(",",$chunks);
$count = count($charray) - 1;
$rand = rand(0,$count);
$chunk = $charray[$rand];
$output = $modx->getChunk($chunk);
return $output;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment