We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10780
    • 69 Posts
    I want to know if I can display an <img> tag only if I have actually added an image into that resource field.

    I have a resource that has has an img field as an option, but if I don’t add one I want that img tag to not appear.

    Any ideas how I go about it?

    Thanks
      • 15175
      • 116 Posts
      You can do this with PHX.

      First install PHX, if you haven’t already:

      http://modxcms.com/extras/package/?package=342

      Then you can add this to your template where your <img> tag would usually be:
      [+phx:if=`[*your-image-tv*]`:is=``:then=``:else=`<img src="[*your-image-tv*]" alt="" />`+]  



      There are probably other ways of doing it.

        • 10780
        • 69 Posts
        Thanks, but I managed to do it like this:

        <?php
        $image = isset($image) ? $image : "";
        if ($image != "") {
            $output = "<img src=\"".$image."\" alt=\"manager Image\"  />";
        } else {
            $output = "";
        }
        return $output;
        ?>


        Now I am trying to do the same thing with tabular data. I basically have tabular data, but sometimes the format of the table is different so I want to be able to enter a custom table. I tried this:

        <?php
        $custom-table = isset($custom-table) ? $custom-table : "";
        if ($custom-table != "") {
            $output = "";
        } else {
            $output = "<table id="costs" summary="Monthly Costs">
        <thead>
        <tr>
        <td class="label">Rent</td>
        <td>£[*rent*]</td>
        </tr>
        <tr>
        <td class="label">Service Charge</td>
        <td>£[*service-charge*]</td>
        </tr>
        <tr>
        <td class="label">Total Monthly Charge</td>
        <td>£[*total-monthly-charge*]</td>
        </tr>
        </table>";
        }
        return $output;
        ?>


        But it’s just not showing up.

        This is how I am calling it:

        [!getTable? &custom-table=``!]
          • 15082
          • 195 Posts
          I think you have to enclose the HTML for the output in single quotes instead of double quotes.

          Greetz
          JUSI
            • 10780
            • 69 Posts
            Hmm, tried that and I get this error:

            Parse error: syntax error, unexpected ’=’ in /home/alphahom/public_html/manager/includes/document.parser.class.inc.php(770) : eval()’d code on line 1

            In fact I get that error with the double quotes.
              • 15175
              • 116 Posts
              Shouldn’t

              if ($custom-table != "")


              be
              if ($custom-table = "")


                • 10780
                • 69 Posts
                Well I want to show the custom table if the custom-table field is not empty, otherwise I want to show the main table.
                  • 10780
                  • 69 Posts
                  Anybody know why I am getting this error:

                  Parse error: syntax error, unexpected '=' in
                    • 4041
                    • 788 Posts
                    I think you should try replacing the dash (-) in the variable name with an underscore and see if that helps:
                    change this:
                    $custom-table

                    to this:
                    $custom_table

                    Maybe give this snippet a try and see if it helps:
                    <?php
                    /*  
                         [!getTable? &custom_table=``!]
                    */
                    $output ='';
                    
                    $custom_table = isset($custom_table) ? $custom_table : '';
                    if ($custom_table != '') {
                        $output .= '';
                    } else {
                        $output .= '<table id="costs" summary="Monthly Costs">
                    <thead>
                    <tr>
                    <td class="label">Rent</td>
                    <td>&#163;[*rent*]</td>
                    </tr>
                    <tr>
                    <td class="label">Service Charge</td>
                    <td>&#163;[*service-charge*]</td>
                    </tr>
                    <tr>
                    <td class="label">Total Monthly Charge</td>
                    <td>&#163;[*total-monthly-charge*]</td>
                    </tr>
                    </table>';
                    }
                    return $output;
                    ?>
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 10780
                      • 69 Posts
                      Hi thanks,

                      I decided in the end to simplify the way I processed the data. But thanks anyway.