MODX Community

How to pass veriable data chunk to snippet

Please tell me how can i pass variable value chunk to snippet … i m written HTML code in chunk and want to send my dropdown field value in snippet.

maybe this is, what you are asking for

It’s difficult to help without knowing where the variable’s value is coming from, but one method is to put the snippet tag where you want the chunk’s HTML to appear and a placeholder in the chunk for the value.


Snippet tag:

Then in the snippet, set the variable to the value and send that to $modx->getChunk() at the end of the snippet:

$myVariable = 'someValue';

return $modx->getChunk('chunkName', array('placeholder_name' => $myVariable));

MODX will return the chunk’s HTML with the placeholder replaced by the value of the variable.