We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39446 ☆ A M B ☆
    • 51 Posts
    Ok so I have seen some people try to answer this in the forums but it never comes out be a straight answer.

    I am trying to find the correct way/package/snippet to use to make an element(TV) only display if something has been inputted in the manager.
    If the user leaves that field blank (in my case it's a downloadable PDF) it should not appear on the page.

    Example of this is here http://64.207.185.174/index.php?id=23
    The right sidebar has a pdf field that is empty and I need it to disappear if it is left empty in the manager.

    Any simple solutions?
      Mahalo,
      Jesse Showalter

      My Portfolio: http://www.jesseshowalter.com
      MODX Video Tutorials: http://jesseshowalter.com/search-results.html?search=MODX&id=22
      • 43288
      • 35 Posts
      Output modifiers would seem to be appropriate here:

      [[!*pdf:notempty=`<a class="download" href="[[*pdf]]"></a>`:else=``]]


      (where pdf is the name of your TV)

      Ideally you wouldn't need the ! (for no caching) or the else= modifier, but there seems to be some occasional bug people have learned to live with where an else= clause is sometimes needed or the logic won't work as expected. I would try it without the ! and :else=`` first because that's how it's supposed to work, but if it doesn't, add those things individually to see if it makes a difference.

        • 39446 ☆ A M B ☆
        • 51 Posts
        Quote from: watou2 at Apr 22, 2013, 06:51 PM
        Output modifiers would seem to be appropriate here:

        [[!*pdf:notempty=`<a class="download" href="[[*pdf]]"></a>`:else=``]]


        (where pdf is the name of your TV)

        Ideally you wouldn't need the ! (for no caching) or the else= modifier, but there seems to be some occasional bug people have learned to live with where an else= clause is sometimes needed or the logic won't work as expected. I would try it without the ! and :else=`` first because that's how it's supposed to work, but if it doesn't, add those things individually to see if it makes a difference.


        This isn't working. I tried all variation of it with "!" without the "!"
          Mahalo,
          Jesse Showalter

          My Portfolio: http://www.jesseshowalter.com
          MODX Video Tutorials: http://jesseshowalter.com/search-results.html?search=MODX&id=22
          • 43288
          • 35 Posts
          Sorry it didn't work, Jesse. If you paste the contents from your right sidebar as you see it in the manager, I might be able to suggest how to change it. My earlier reply was based on guesswork from what the actual resource shows.

          Mahalo,
          watou
            • 38290
            • 712 Posts
            Using output modifiers as mentioned should definitely work here. Of course there is also the If Extra which can be more legible but would be overkill in this case
              jpdevries
              • 3749
              • 24,544 Posts
              I would do it with a snippet called PDF (this assumes that the TV is called pdf and contains just the path to the .PDF file):

              [[!PDF]]


              <?php
              /* PDF snippet */
              
              $tv = $modx->resource->getTVValue('pdf'); // name of the TV here
              $tv = urlencode($tv); // might need this if there are spaces in the file or dir names
              return !empty ($tv) ? '<a class="download" href="' . $tv . '"></a>' : '';
              
              

                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
                • 39446 ☆ A M B ☆
                • 51 Posts
                Quote from: BobRay at Apr 23, 2013, 12:45 AM
                I would do it with a snippet called PDF (this assumes that the TV is called pdf and contains just the path to the .PDF file):

                [[!PDF]]


                <!--?php
                /* PDF snippet */
                
                $tv = $modx--->resource->getTVValue('pdf'); // name of the TV here
                $tv = urlencode($tv); // might need this if there are spaces in the file or dir names
                return !empty ($tv) ? '<a class="download" href="' . $tv . '"></a>' : '';
                
                


                Thanks Bob,

                Output modifiers weren't working for some reason, but the snippet is a sure fire way. I appreciate you advice.
                Side note:
                Bob your resources on your blog are great, but you should really think about a redesign, contact me if your interested smiley
                  Mahalo,
                  Jesse Showalter

                  My Portfolio: http://www.jesseshowalter.com
                  MODX Video Tutorials: http://jesseshowalter.com/search-results.html?search=MODX&id=22
                  • 3749
                  • 24,544 Posts
                  Are you referring to BobsGuides in general, to my blog there, or to my other blog?
                    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
                    • 39446 ☆ A M B ☆
                    • 51 Posts
                    Quote from: BobRay at Apr 23, 2013, 10:08 PM
                    Are you referring to BobsGuides in general, to my blog there, or to my other blog?

                    Bob's Guides. Very useful, but not to friendly on the eye.
                    check me out if interested jesseshowalter.com
                      Mahalo,
                      Jesse Showalter

                      My Portfolio: http://www.jesseshowalter.com
                      MODX Video Tutorials: http://jesseshowalter.com/search-results.html?search=MODX&id=22
                      • 3749
                      • 24,544 Posts
                      Periodically, I think about doing a little work on it, but I always have at least five or six projects I want to finish first.

                        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