We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39059
    • 11 Posts
    I've been working on a new client's website, and they have been using ModX for a while, so I started working with it as is .. I've dabbled with other CMS's and none of them impressed me, and I went into this with an open mind, but skeptical. Turns out, I love ModX, it's powerful, flexible and for the most part easy to use. However, there is one problem that I'm trying to figure out how to solve.

    I have furl working properly on Win7/IIS (or at least properly enough, but that's a topic for another separate thread). And, so, with the page name, I have a corresponding image that I would like to show, seems simple enough to throw in the [[Alias]] variable, and work with that. However, some pages don't have corresponding images, and I would like to know if I should use TV's, or some other method of showing the proper image when there is one and not showing the stupid blank placeholder icon when there isn't a corresponding image?
      • 19369
      • 1,098 Posts
      With conditional statements you can remove the image if the Template Variable is empty.

      For Revolution:

      http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
      http://rtfm.modx.com/display/ADDON/If
      https://forums.modx.com/thread/32601/andif---conditional-snippet-allowing-multiple-and-or-conditions

      I'd go with the If or AndIf snippet because heavy usage of output modifiers can slow down the website.

      For Evolution:

      http://wiki.modxcms.com/index.php/PHx#Advanced_usage
        • 4172
        • 5,888 Posts
        you can create a little 'fileexists' - snippet, which checks for the existence of the file and does only return the img-tag, if it exists.
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 39059
          • 11 Posts
          @bruno - do you have a reference for this FileExists snippet?

          @micro - I tried looking at TV's, but I couldn't get a grasp of them. Am I able to fill in the TV with a specific value from an individual page? If so, how would I do that?
            • 19369
            • 1,098 Posts
            Quote from: rolaaus at Apr 05, 2012, 12:04 AM
            Am I able to fill in the TV with a specific value from an individual page? If so, how would I do that?

            Yes, that's what a TV is meant to do. A TV is a Custom Field which is assigned to a specific template. Let me know if you are using Revolution or Evolution first (the procedure is slightly different).
              • 4172
              • 5,888 Posts
              didn't try this, but something like that schould do it:

              snippet:

              <?php
              //[[chunkIfFileExists? &tpl=`myImgTpl` &filename=`[[+pagetitle]]` &filepath=`assets/images/`]]
              
              
              $properties = $scriptProperties;
              $properties['file_url'] = $modx->getOption('base_url').$filepath.$filename;
              
              return file_exists($modx->getOption('base_path').$filepath.$filename) ? $modx->getChunk($tpl,$properties) : '';
              


              chunk myImgTpl:

              <img src="[[+file_url]]" />
              


              your snippet-tag:
              [[chunkIfFileExists? &tpl=`myImgTpl` &filename=`[[+pagetitle]]` &filepath=`assets/images/`]]
              


              if it works you can put more properties and get them as placeholders in your chunk.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 39059
                • 11 Posts
                @Micro - I'm using Revo. Thanks

                @Bruno - I'll have to save this method as a back-up in case I can't get it to work otherwise. I'm not that familiar with Java coding, but if it comes down to it, I known enough "programming" to search on-line and find something close enough to work and tweak it to my needs, if it doesn't meet my need as-is. Thanks
                  • 19369
                  • 1,098 Posts
                  Ok, try this:

                  1)
                  Go to "Elements > New TV"

                  2)
                  TV Name: image
                  Caption: Image
                  Input Type: image
                  Template Access: choose in which template you need the image TV
                  Save

                  3)
                  Install If Snippet.

                  4)
                  Open your Template or your Chunk and add a code like this:
                  [[If? 
                  	&subject=`[[*image]]` 
                  	&operator=`=` 
                  	&operand=`` 
                  	&then=`` 
                  	&else=`<img src="[[*image]]" alt="#" />`
                  ]]
                    • 39059
                    • 11 Posts
                    @Micro, Okay, I've got you so far, I've created the variable (I called it 'myImage' because I try not to use any variable name that could possibly be a 'reserved word'). And I completely understand your IF statement - what it does, etc., but how do I actually fill the variable with the filename of the picture I want to use for each different page?

                    I have named the images to correspond with each page, but not every page has an image, so as I mentioned before, for those pages that don't have images, I'm getting the placeholder icon showing up.
                      • 19369
                      • 1,098 Posts
                      Quote from: rolaaus at Apr 05, 2012, 02:55 PM
                      how do I actually fill the variable with the filename of the picture I want to use for each different page?

                      After that you have assigned the TV to a template you need to open the page itself from the "Resources" Tab. Once you open the page, go to "Template Variables" tab: here you should see your Image TV, click there to upload or select an image for that page.

                      Is this what you are looking for?