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

    I have a chunk which I want to display the unpublish date if there is one - I thought this would work:

    [[*unpub_date:notempty=`
    	<p>Offer expires on [[*unpub_date:strtotime:date=`%e %B %Y`]]</p>
    `]]
    


    Which works if the unpublish date IS set, but if it's not, it displays an unstyled '0' (zero) instead..

    Any ideas?

    Thanks
    Andy

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 51020
      • 670 Posts
      UPDATE:

      After playing around with various output modifiers, i realised that if I just show [[*unpub_date]] - it output '0' (zero). So I tried:
      [[*unpub_date:isnot=`0`:then=`
      


      And it works!

      Where there's a will, there's a way! lol
      Andy
      • discuss.answer
        • 3749
        • 24,544 Posts
        Another (somewhat faster) way to go would be a very short snippet

        [[!unpubDate]


        /* unpubDate snippet */
        $unpubDate = $modx->resource->get('unpub_date');
        return empty($unpubDate)? "" : '<p>' . strftime('%e %B %Y', strtotime($unpubDate)) . '</p>';
        // Adjust HTML as necessary
        





          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
        • discuss.answer
          • 51020
          • 670 Posts
          Quote from: BobRay at Oct 13, 2017, 12:48 AM
          Another (somewhat faster) way to go would be a very short snippet

          [[!unpubDate]


          /* unpubDate snippet */
          $unpubDate = $modx->resource->get('unpub_date');
          return empty($unpubDate)? "" : '<p>' . strftime('%e %B %Y', strtotime($unpubDate)) . '</p>';
          // Adjust HTML as necessary
          


          Thanks Bob - I knew you would have a more graceful solution!
          So do you mean this is faster in terms of server performance?

          Andy
            • 3749
            • 24,544 Posts
            Yes, but don't thank me until it works. wink
              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