Created
October 21, 2011 02:45
-
-
Save digibutt/1302987 to your computer and use it in GitHub Desktop.
getResourceAsPlaceholder
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 | |
/* | |
Call it like this: | |
[[getResourceAsPlaceholder? | |
&id=`10` | |
&prefix=`doc.` | |
&separator=`.` | |
&merge=`1` | |
&longtitle=`lorem ipsum` | |
]] | |
Merge will set longtitle to lorem ipsum if the resource field is empty. | |
*/ | |
if(!$resource = $modx->getObject('modResource', $id)){ | |
return; | |
} | |
$prefix = $modx->getOption('prefix', $scriptProperties, ''); | |
$separator = $modx->getOption('separator', $scriptProperties, ''); | |
$tvs = $resource->getMany('TemplateVars'); | |
$resourceArray = array(); | |
foreach($tvs as $tvId => $tv){ | |
$resourceArray[$tv->get('name')] = $tv->renderOutput($resource->get('id')); | |
} | |
$resourceArray = array_merge($resourceArray, $resource->toArray()); | |
if($merge == '1'){ | |
foreach($resourceArray as $key => $val){ | |
$resourceArray[$key] = ($scriptProperties[$key] == '') ? $val: $scriptProperties[$key]; | |
} | |
} | |
$modx->toPlaceholders($resourceArray, $prefix, $separator); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment