Created
March 26, 2013 20:21
-
-
Save jrotering/5248862 to your computer and use it in GitHub Desktop.
Simple snippet that returns the name (or any other field you specify) of any MODX object. Example:
[[getObjectName?&obj=`modTemplate`&id=`[[*template]]`]]
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 | |
$fn = (isset($field)) ? $field : ($obj == 'modTemplate') ? 'templatename' : 'name'; | |
if ($object = $modx->getObject($obj, $id)) { | |
if ($value = $object->get($fn)) { | |
return $value; | |
} | |
else { | |
$modx->log(modX::LOG_LEVEL_ERROR, 'getObjectName - could not find field "' . $fn . '" on object #' . $id . ' of type "' . $obj . '"'); | |
} | |
} | |
else { | |
$modx->log(modX::LOG_LEVEL_ERROR, 'getObjectName - could not retrieve object #' . $id . ' of type "' . $obj . '"'); | |
} | |
return ''; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment