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

    I’ve added a image to a template using a TV, now in the template I have the following code:

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


    Now my problem is that this is used on several templates and if no image is added (not all articles have them) IE is displaying the little red x for a broken image.

    Is there anything I can use to say if there is a image echo the above code out, but if not don’t echo it out and therefore fix my problem as I don’t want to go down the route of having every template reproduced for no image.

    Thanks
      • 33982 ☆ A M B ☆
      • 476 Posts
      Hey paulp...here’s the easiest way I know to fix this: use PHx (http://modxcms.com/PHx-1006.html) ... I use it all the time for this. What you would do is install PHx and then put the following in your template:

      [*image:is=``:then=``:else=`<img src="[*image*]" />`*]


      Try it out and let me know if you have any problems.
        Precision Web Development ... SmashStack.com
        • 7231
        • 4,205 Posts
        Try something like this:
        <?php
        $image = isset($image) ? $image : "";
        if ($image != "") {
            $output = "<img src=\"".$image."\" />";
        } else {
            $output = "";
        }
        return $output;
        ?>


        Then use the snippet like this: [!getImage? &image=`[*image*]`!]
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 16183
          • 1,390 Posts
          Quote from: flinx at Aug 29, 2008, 11:26 AM

          Hey paulp...here’s the easiest way I know to fix this: use PHx (http://modxcms.com/PHx-1006.html) ... I use it all the time for this. What you would do is install PHx and then put the following in your template:

          [*image:is=``:then=``:else=`<img src="[*image*]" />`*]


          Try it out and let me know if you have any problems.

          Paulp, don’t mean to hijack your thread. I have a similar question so thought to post it here.

          @Flinx/dev_cw, etc, I think I read this somewhere on the forums but cannot seem to find it now. I think PHx would do the job but am not sure. Say I had a 3-column template - left one for menu, middle one for content and right one for news bits. Can I use some PHx function to automatically hide the right column if it was empty (if no news) and at the same time automatically expand the middle column to fill the space left by the right column? How would the PHx call look like? I hope my question’s clear.

          Secondly, is there an alternative to using PHx to achieve the same thing described above, say some CSS code? Thanks
            • 7231
            • 4,205 Posts
            with PHx you would have a sidebar chunk that would be displayed it some variable has content (depending on how the sidebar content is built). Yo would use the standard if not empty do this.

            The same principal of the snippet above would also work where instead of the image it would return the correct chunk (with sidebar or without).

            You could probably do this with a javascript library like jQuery as well.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 16183
              • 1,390 Posts
              Thx Shane..

              /k
                • 16183
                • 1,390 Posts
                Quote from: dev_cw at Aug 29, 2008, 02:15 PM

                with PHx you would have a sidebar chunk that would be displayed it some variable has content (depending on how the sidebar content is built). Yo would use the standard if not empty do this.

                The same principal of the snippet above would also work where instead of the image it would return the correct chunk (with sidebar or without).


                @ dev_cw, etc.

                Sorry to bother you again Shane. Please excuse the newbie questions. I have looked at the PHx wiki (and also googled) but still have no idea how both the PHx call and the chunk would look like. Would you mind pointing me to some example or writing some example code here for me to see? Thanks in advance.

                /k
                  • 3707
                  • 241 Posts
                  You don’t need to use PHx to hide/expand a side column, you can build a template using CSS to control the display of columns. If your central content column has a width of 100% set and the side columns are floated, removing the side columns will allow the main content column to expand to fill the whole space.

                  If you use Ditto to generate the news content, the template chunks output the code for the news column. You can then use the noResults parameter to output a different chunk which doesn’t contain the news column code. Since the news column container isn’t present, the main content column will expand.
                    • 16183
                    • 1,390 Posts
                    Brilliant, thx bob1000 for this alternative. I get it now.

                    Cheers,
                    /k
                      • 22840
                      • 1,572 Posts
                      Thanks for the replies.

                      I used the PHP example as it was the quickest and it worked a treat.

                      Thanks allot