Skip to content

Instantly share code, notes, and snippets.

@sonicpunk
Created November 14, 2013 13:16
Show Gist options
  • Save sonicpunk/7466595 to your computer and use it in GitHub Desktop.
Save sonicpunk/7466595 to your computer and use it in GitHub Desktop.
MODX Snippet. It accepts a comma separated list of chunk names and randomly picks one for output. I used it to randomly assign class names to an html element. Example usage: <body class="color-1 h-style-1 text-1 [[!randomChunk? &chunks=`cloud1,cloud2,cloud3,cloud4`]]">
<?php
$output='';
$chunkArray=explode(',',$chunks);
$randomKeys=array_rand($chunkArray);//pick random key
$randomChunkName=$chunkArray[$randomKeys];
$output.=$modx->getChunk($randomChunkName);
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment