I’ve never played around with RandomParagraph, but I took a look at the code. First, I created a testsnippet that just returned some text and the values of passed parameters. Then I replaced the last line of the RandomParagraph code with this
//return str_replace('[+rp.paragraph+]', $results[$method][$rand], str_replace('[+rp.sourcePageUrl+]', $modx->makeUrl((int)$pageId), $template));
$output1 = str_replace('[+rp.paragraph+]', $results[$method][$rand], str_replace('[+rp.sourcePageUrl+]', $modx->makeUrl((int)$pageId), $template));
$output2 = trim($output1);
$snippet_flag = ((strpos($output2, '[!') && strpos($output2, '!]')) || (strpos($output2, '[[') && strpos($output2, ']]'))) ? true : false;
if ($snippet_flag)
{
$output2 = str_replace('[!','',$output2);
$output2 = str_replace('!]','',$output2);
$output2 = str_replace('[[','',$output2);
$output2 = str_replace(']]','',$output2);
$with_params_flag = strpos($output2,'?');
if ($with_params_flag)
{
$snippet_ra = explode('?',$output2);
$snippet_name = $snippet_ra[0];
$snippet_params = explode('&', $snippet_ra[1]);
$passed_params = array();
foreach ($snippet_params as $key => $value)
{
$temp_ra = explode("=",$value);
$passed_params[$temp_ra[0]] = $temp_ra[1];
}
$output2 = $modx->runSnippet('testsnippet',$passed_params);
}
else
{
$output2 = $modx->runSnippet('testsnippet',array());
}
}
return $snippet_flag ? $output2 : $output1;
The document that this referred to had three "p" tags : the first two were random text, the third was a call to ’testsnippet’.
The above amended version of RandomParagraph correctly returned either the random text or the output of the snippet.
That said, I didn’t figure out how to pass the snippet name by a variable (e.g. how to use $snippet_name instead of the hardcoded ’testsnippet’) in my quick look. And the values being passed to the snippet included the backslashes, so that would probably need to be changed. And, of course, the entire block of code could probably be written in a much tighter fashion. However, maybe it’s a start.
Regards,
Matt