Not much to this one, but fills in some functionality that appears to be missing from MODx. If this functionality already exsists somewhere, let me know.
Snippet name: [[SuperChunk]]
Description: Get a chunk then find and replace given placeholders
<?php
/*******************************************************************\
| Snippet Name: SuperChunk |
| Created By: Alastair L. Drong |
| Last Modified: Alastair L. Drong 02/12/07 |
| Input: &scChunkName -- name of the chunk to use |
| &sc_csv_PeqV -- user defined placeholder=value |
| Output: returns chunk with values ('V') |
| substituted for placeholders ('P') |
\*******************************************************************/
$scChunk=isset($scChunkName)? $modx->getChunk($scChunkName):'';
$sc_strAr_PeqV=isset($sc_csv_PeqV)? explode(', ', $sc_csv_PeqV):array('error_eq_error');
foreach($sc_strAr_PeqV as $scV)
{
$scTmpP0V1=explode('_eq_', $scV);
$scChunk=str_replace('[+'.$scTmpP0V1[0].'+]', $scTmpP0V1[1], $scChunk);
}
return $scChunk;
?>
Chunk name: scPageFormat
here’s the chunk my example will use:
<img src="[+chicagoIMG+]"><br />[+salutation+]
Here’s a simple example on use:
[[SuperChunk? &scChunkName=`scPageFormat` &sc_csv_PeqV=`salutation_eq_hello, chicagoIMG_eq_http://euclid.nmu.edu/~adrong/jpegs/chicago/IMG_1698.jpg`]]
output should be:
<img src="http://euclid.nmu.edu/~adrong/jpegs/chicago/IMG_1698.jpg"><br />hello
I haven’t tested it much yet, so I don’t promise it’ll handle all input (white space, unusual characters like é or ~) exactly as it should. Next update will support commas in output.