Simple Example:
Lets process this chunk and output its value. We have this Chunk, called "Welcomechunk":
< P > Welcome [[+name]]! </ P >
We ' ll put this on 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 Insid e the chunk, e.g. [[+name]
< P > Welcome john! </ P >
Nested $properties
In our Chunk:
<href= "http://site.com/profile?user_id=[[+user.id]]!" > User Details</a>
In our Snippet:
$output $modx->getchunk (' Userlink ', Array (' id ' = + 123); return $output;
parsing a String
Sometimes you need to parse a string using the MODX parser–this does isn't use GetChunk, but it's related. Using the MODX parser is a bit slower than using a simple str_replace function, but it does let's use complex Placeholde RS (e.g to include another Chunk) and output filters etc. The trick is to create a temporary Chunk object and then run the process method on it.
//The formatting String$TPL= ' Hello, my name is [[[+name]] '; //Properties$props=Array(' name ' = ' Bob '); //Create the temporary chunk$uniqid=uniqid();$chunk=$modx->newobject (' Modchunk ',Array(' name ' = ' = ' {tmp}-{$uniqid}"));$chunk->setcacheable (false); $output=$chunk->process ($props,$TPL);
See:http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.getchunk
[MODx] 8. Snippet get data, chunk display