Hi,
I’m writing a snippet that should output chunks randomly. These chunks contain snippet calls.
This is the current state of the snippet [[randomVoicebox]]:
<?php
$voice = array('{{voicebox-1}}','{{voicebox-2}}','{{voicebox-3}}');
$rand = rand(0, (count($voice)-1)); // Generate a random number between zero and the number of chunks minus one
$voice = $modx->evalSnippets($voice); // Parse snippet tags in string
$output = $voice[$rand]; // Output the random chunk
return $output;
?>
This is the Modx error I get:
PHP error debug
Error: preg_match_all() expects parameter 2 to be string, array given
Error type/ Nr.: Warning - 2
File: /var/www/vhosts/blah.co.uk/subdomains/indev/httpdocs/manager/includes/document.parser.class.inc.php
Line: 786
Line 786 source: preg_match_all(’~\[\[(.*?)\]\]~ms’, $documentSource, $matches);
This is an example of one of the chunks (voicebox-1):
[!getField? &docid=`1` &field=`voicebox-photo`!]
[!getField? &docid=`1` &field=`voicebox-name`!]
Using the: getField snippet here: http://modxcms.com/extras/package/?package=173
This is my snippet call in the template:
Modx version: 1.0.2
Can anyone help out? Thanks.