Skip to content

Instantly share code, notes, and snippets.

@Realetive
Last active June 29, 2016 10:31
Show Gist options
  • Save Realetive/abd9bc46ec5bcefe196ec1fa9ae65e22 to your computer and use it in GitHub Desktop.
Save Realetive/abd9bc46ec5bcefe196ec1fa9ae65e22 to your computer and use it in GitHub Desktop.
Фильтр MODX, парсит строку и выводит по шаблону: [[+placeholder:stringParser=`{ "delimiter" : ", ", "tpl" : "@inline [[+item]]" }`]]
<?php
/**
* MODX output filter
* Parse string from [[+placeholder]] and wrap every item with tpl.
* Parameters as JSON keys, tpl can be set as chunk name :
* [[+placeholder:stringParser=`{ "delimiter" : ", ", "tpl" : "my_chunk`]]
* or with @INLINE:
* [[+placeholder:stringParser=`{ "delimiter" : ", ", "tpl" : "@INLINE [[+item]]" }`]]
* Requrements: pdoTools.
*/
if(empty($input)){
return;
}
$param = json_decode( $options, true );
$arr = array_map( "trim" , explode($param[ 'delimiter' ], $input) );
$result = '';
for( $i = 0; $i < count($arr); $i++ ){
$result .= $modx->getService('pdoTools')->getChunk($param[ 'tpl' ], array(
"item" => $arr[ $i ],
) );
}
return $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment