We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Hopefully a simple one.

    I created a TV with the sole responsibility of inserting an image on a certain part of a page, which can be chosen by a user in the back end. What I did was:

    1. Start a new TV, gave it a name, caption, description and an input type of ’Image’. Assigned the TV to all my templates.
    2. In the template, I added this at the spot I want these images to appear:

    <img src="[[*name_of_my_tv]]" />


    3. In the resource, I found the TV and went ahead and inserted the image, following the steps presented.

    All worked great for that page. The image came up beautifully.

    ...however...

    On all the other resources where I don’t have an image inserted by way of that TV, I get a broken image icon where the code exists (with the exception of Firefox). When I look at the source code, I notice I see an empty image tag, like this:

    <img src="" />


    Obviously the system is good at noticing an empty TV, but not the rest of the code. What is the correct procedure to implement the ’Image’ input type on a page? I would like the site editor to be able to place an image on there or not, at will, without needing to have to edit any html inside a chunk or whatever.

    Thank you in advance.

    Revo 2.0.8
    PHP Version 5.2.10
      • 23571
      • 223 Posts
      You can use filters: http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
      Or the If snippet: http://rtfm.modx.com/display/ADDON/If

      Basically check to see if TV is empty and return nothing if it is empty or return the image tag with the TV pathway.
        • 31902
        • 342 Posts
        Quote from: pleth at Mar 30, 2011, 11:12 AM

        You can use filters: http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
        Or the If snippet: http://rtfm.modx.com/display/ADDON/If

        Basically check to see if TV is empty and return nothing if it is empty or return the image tag with the TV pathway.

        Sounds interesting... can you elaborate for a newbie like me? How exactly would I employ it? What code would I use and where?
          • 23571
          • 223 Posts
          With the If snippet it would be something like: [[!If? &subject=`[[*yourTV]]` &operator=`empty` &then=`` &else=`<img src="[[*yourTV]]" />`]]
            • 31902
            • 342 Posts
            Quote from: pleth at Mar 30, 2011, 03:27 PM

            With the If snippet it would be something like: [[!If? &subject=`[[*yourTV]]` &operator=`empty` &then=`` &else=`<img src="[[*yourTV]]" />`]]

            Beautiful...works like a charm. Thank you pleth!