We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8609
    • 607 Posts
    Quote from: Everett at May 30, 2011, 11:48 PM

    Ok, here’s the little custom Output Filter Snippet I wrote, named lookupContentType:

    <?php
    $CT = $modx->getObject('modContentType', $input);
    
    return $CT->get('name');


    I’m using it in a Wayfinder call, e.g. here’s my rowTpl Chunk:

    <a href="[[+wf.link]]">[[+wf.pagetitle]]</a> [ [[+wf.content_type:lookupContentType]] ]<br />
    		[[+wf.introtext]]
    


    Works perfectly!! Thanks for sharing smiley


    is there a placeholder for content disposition?

    [[+content_dispo]] But again this gives you the ID. Work your magic smiley
      • 28215
      • 4,149 Posts
      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. smiley

      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.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        For some reason, the cached version there started spitting out "HTML" for everything, even after the cache was cleared.

        Is there a placeholder for whether the resource is a WebLink vs. a Static Resource vs. a regular Resource?
          • 28215
          • 4,149 Posts
          [[+class_key]]
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com