Created
November 14, 2013 13:16
-
-
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`]]">
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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