modX::getChunk
Processes and returns the output from an HTML chunk by name.
Syntax
API Doc: http://api.modxcms.com/modx/modX.html#getChunk
string getChunk (string $chunkName, [array $properties = array ()])
Examples
Simple Example
Lets process this chunk and output its value. We have this Chunk, called "WelcomeChunk":
<p>Welcome [[+name]]!</p>
We'll put this in our Snippet:
$output = $modx->getChunk('WelcomeChunk',array(
'name' => 'John',
));
return $output;
So every key in the associative array passed to the getChunk method corresponds to an available placeholder inside the chunk, e.g. [[+name]]
This code outputs this:
<p>Welcome John!</p>
Used in a Snippet
Often, MODX Chunks are used as formatting string by Snippets. To that end, you can make good use of xPDO's toArray() method.
Imagine a Chunk named single_user:
Username: [[+username]]<br/> Active?: [[+active]]<br/> <hr/>
Then in your Snippet:
$userlist = $modx->getCollection('modUser');
$output = '';
foreach ($userlist as $user) {
$output .= $modx->getChunk('single_user', $user->toArray() );
}
return $output;