I’ll will start my first contribution in the documentation then.
Here is a set of API that you need to start making a chunk base template with placeholde.
WARNING: mergeChunkContent & mergePlaceholderContent is not included as a global API for MODx. It might not be supported in the future release. You’ve been warned; use it with caution!
setPlaceholder
function setPlaceholder($name,$value)
This API will basically store the $value variable into placeholders array with the associated key name from the given $name. The placeholder array, later will substitute the placeholder that are being included in a page (template, chunk, or content), with the format of "[+placeholder_name+]", without the quote.
getPlaceholder
function getPlaceholder($name)
This is the opposite API of sePlaceHolder, which it will return the value of placeholder array with the given $name as the key name.
parseChunk
function parseChunk($chunkName, $chunkArr, $prefix="{", $suffix="}")
We can use this function to substitute any special format string inside the chunk to be replaced by the value of the array. The given $chunkName will be the name for the chunk, and $chunkArr will be an associative array that is going to be used to substite the special format string inside the chunk, and the $prefix and $suffix is used to differentiate the special format string inside the chunk, default is "{" and "}". The associative array key name of $chunkArr will be used as a special format string name that is being prefixed by $prefix and $suffix. The $prefix and $suffix can be left blank for default value
Example:
This is an example of the chunk with the name "SampleChunk"
This is the template
Here is the special string format {SPECIAL1}
This is an example of the snippet using parseChunk
// Storing value to replace special format string into associative array
$ChunkVar['SPECIAL1'] = "Hello World!";
echo $modx->parseChunk("SampleChunk", $ChunkVar);
The snippet above will output
This is the template
Here is the special string format [color=blue]Hello World![/color]
The function listed under here is not suggested to be used for production snippet, plugin, or module!
mergePlaceholderContent - WARNING: Non-Global API
function mergePlaceholderContent($content)
This function will combined the placeholders array that was set earlier (setPlaceholder) with the given string template, which was passed on to $content. It will replace "[+key_name+]" symbol in the template with the value on the array with the same key name. The rest of the placeholders symbol that are not associated with everything will be remove and substituted with empty string.
mergeChunkContent - WARNING: Non-Global API
function mergeChunkContent($content)
This API will fetch a chunk based on their name, when it was stored inside the manager. We need to pass on a string with the format as when we are included chunk to the template or content "{{chunk_name}}", without the quote.
Tips to use this for chunk base template on MODx Using Non-Global API
Please read the example carefully, to get a grasp of the whole idea.
$chunk_name = 'samplechunk'; // Assign chunk name to this variable
// Setup placeholders
$modx->setPlaceHolder('NamePlaceholder1', 'This is the value for placeholder 1');
$modx->setPlaceHolder('NamePlaceholder2', 'This is the value for placeholder 2');
// Getting chunk template and store it to variable
$template = $modx->mergeChunkContent("{{".$chunk_name."}}")."\n";
// Merging placeholder with template
$output = $modx->mergePlaceholderContent($template);
// Outputing result to the screen
echo $output;
Happy MODx-ing guys!