Passing a parameter to a chunk in MODx
I wanted to pass a parameter or variable directly to a chunk in MODx 0.9.6

Apparently this is only possible in the REVO version of MODx. So Instead I needed to create a snippet to call the chunk and pass the parameter as a placeholder. Rather than doing it for this for a single purpose, I made it so any parameter name can be passed, allowing for a bit more flexibility.

/*
::::::::::::::::::::::::::::::::::::::::
Snippet name: PassParameter
Short Desc: passes a parameter to a chunk as a placeholder
Date: May 29, 2009
Author: Daniel Poda
::::::::::::::::::::::::::::::::::::::::
Description:
pass parameter defined by &pName and &pVal to a chunk &tpl
set &preparse to 1 (TRUE) to parse the chunk before returning the content
by default this does not pre parse
::::::::::::::::::::::::::::::::::::::::
Usage:
[[PassParameter? &tpl=`myChunk` &pName='param' &pVal='12' &preparse='1']]
*/

$params[$pName]=$pVal;

if ($preparse== 1){
$documentOutput.=$modx->parseDocumentSource($modx->parseChunk($tpl, $params, '[+', '+]'));
}
else{
$documentOutput.=$modx->parseChunk($tpl, $params, '[+', '+]');
}

echo($documentOutput);
?>


usage
[[PassParameter? &tpl=`myChunk` &pName='param' &pVal='12' &preparse='1']]
Posted on 2009 May 29 by Daniel

(optional)

smile wink wassat tongue laughing sad angry crying 


Enter the code shown in the image:


| Forget Me
Content Management Powered by CuteNews