FYI, I’d improve that a bit:
<?php
$cacheKey = $modx->resource->getCacheKey().'content-type';
$ct = $modx->cacheManager->get($cacheKey);
if (empty($ct)) {
$ct = $modx->getObject('modContentType', $input);
$ct = $ct ? $ct->get('name') : '';
}
if (!empty($ct)) {
$modx->cacheManager->set($cacheKey,$ct,3600);
}
return $ct;
Otherwise if there’s no content type found for some reason you’re gonna end up with nice 500 errors.
This also caches the result in the Resource’s cache, so it loads much faster; and will clear if you clear that Resource’s cache.