We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28444
    • 6 Posts
    Hello all,

    I have a listing of downloadable items and I have to output an icon corresponding to each child’s contentType.

    My Ditto template is:

    <div>
    [+title+]
    <br />
    Download: <a href="[+url+]" title="[+title+]">[+title+]</a>
    <br />
    Published on: [+pubdate+]
    <br />
    By: [+author+]
    <br />
    File type: [+contentType+]
    </div>
    



    [+contentType+] correctly outputs application/pdf, but how can I change it to smth like: <img src="/icons/pdf.png" title="pdf" />?

    Thank you.
      • 16278
      • 928 Posts
      You can use a PHx custom modifier to manipulate output of the placeholder. E.g. create a snippet called phx:typeImage
      <?php
      //phx:typeImage
      //PHx modifier to associate content types with images
      //
      // usage: [+placeholder:typeImage+]
      // placeholder value is in $output
      
      switch ($output) {
      	case 'application/pdf':
      		$result = '<img src="/icons/pdf.png" title="pdf" />';
      		break;
      	case  'text/plain':
      		$result = '<img src="/icons/notepad.png" title="text" />';
      		break;
      	default:
      		$result = '???';
      }
      
      return $result;
      ?>


      PHx is built in to Ditto, so all you need to do in your chunk is send the placeholder’s output to the modifier like this:
      File type: [+contentType:imageType+]


      (not tested!)
      smiley KP
        • 28444
        • 6 Posts
        Thanks a bunch. Works like a treat!