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


    I have a tv containing the cliché info like this
    {"id":"7","thumbwidth":"220","thumbheight":"160","tv":"1","resource":"5","x":"4","y":"0","x2":"217","y2":"155","w":"213","h":"155","image":"/assets/components/cliche/albums/2/wrc.png","thumbnail":"/assets/components/cliche/cache/2/7/wrc-220x160-doc5-tv1.png","timestamp":1354626317}


    I'm trying to get the "image" or thumbnail values into a chunk like this one (where summaryFooterImg is the name of my tv that i'm getting from a getresource snippet)

    <div class="summaryFooter" style="background:url([[+tv.summaryFooterImg.image]]) center no-repeat"></div>


    Any idea?

    Thanks
      • 52634
      • 60 Posts
      Recently ran into the same problem. Cliche TV value is stored as JSON array. Simplest solution for me: creation of a custom output filter to get a field value from JSON (wondering why such an output filter is not integrated into core by default?).

      First create a snippet called "json" like this shorty:
      <?php
      if (!empty($input) && $input != '{}') {
          $data = $modx->fromJSON($input);
          /* return the field with name in options */
          if (!empty($options) && !empty($data)) {
              return $data[ $options ];
          }
      }
      return '';
      

      This snippet can then be used as an output filter for your TV:
      <div ... style="background:url([[+tv.summaryFooterImg:json=`image`]]) ..."></div>

      Should work straightforward. We used this to produce different phpthumbed-versions of one cliche tv thumbnail.