Last active
June 29, 2016 10:31
-
-
Save Realetive/abd9bc46ec5bcefe196ec1fa9ae65e22 to your computer and use it in GitHub Desktop.
Фильтр MODX, парсит строку и выводит по шаблону: [[+placeholder:stringParser=`{ "delimiter" : ", ", "tpl" : "@inline [[+item]]" }`]]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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