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

    I have a tv to set a thumbnail image for a news article, the thumbnail is then displayed in the article summary on the articles page created using getResources - very standard stuff.
    I'm trying to write a snippet to test whether or not the thumbnail tv ios set or not - if it is set then I want the thumbnail to display if not then I don't.

    so far I have this:

    /* Get the TV */
    $tv = $modx->getObject('modTemplateVar',array('name'=>'pageThumb')); //pageThumb is the name of the tv
    
    /* get the raw content of the TV */
    $rawValue = $tv->getValue($id); //$id is the id of the news article page, passed to the snippet via the snippet call
    
    if($rawValue != ''){
    
    $output = $modx->getChunk('summaryBoxImage');
    return $output;
    
    }


    Based on the Bob's guides article: http://bobsguides.com/revolution-objects.html

    But it doesn't work.

    Any help would be greatly appreciated.

    Thanks in advance!
      • 3749
      • 24,544 Posts
      Could you give more details about what you're seeing? "Doesn't work" is kind of vague. wink

      Are you testing the snippet on its own before putting it in the getResources tag (a good idea)?

      Also, try this:


      /* Get the TV */
      $tv = $modx->getObject('modTemplateVar',array('name'=>'pageThumb')); //pageThumb is the name of the tv
       
      if (!$tv) {
         return 'Could not get TV';
      }
      /* get the raw content of the TV */
      $rawValue = $tv->getValue($id); //$id is the id of the news article page, passed to the snippet via the snippet call
       
      if($rawValue != ''){
          $output = $modx->getChunk('summaryBoxImage');
          return $output;
      } else {
          return 'rawValue is empty';
      }
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 31902
        • 342 Posts
        Hopefully, I understand what is you're trying to do:

        Does it have to be within the getResources code? If you can do your solution on the page, I usually use the If component and set up the code using something like this:

        [[!If? &subject=`[[+tv.yourTV]]` &operator=`empty` &then=`` &else=`<div id="div_to_float_left_or_right_of_summary"><img src="[[+tv.yourTV]]" /></div>`]]


        Then, set up the CSS to make that div float left or right. If there is nothing within the

        [[+tv.yourTV]]


        ...then no sweat. It just doesn't appear. The rest of the summary's css should be written to fill up the space. Did that make sense?

        [ed. note: waizen last edited this post 13 years, 7 months ago.]