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

    I have a simple news summary page using Ditto which is working great. The only issue arrises if there isn’t an intro image for a news item. Then a missing image icon appears on the summary page. Is it possible to have Ditto strip the image html out if no image is present?

    I thought about trying some PHx (I have no programming experience) but got stuck on how to include the image html into the argument. I have an intro image TV that is formatted in the Ditto template like this:
    <a href="[~[+id+]~]"><img class="floatLeft" src="[+introImage+]" alt="[+introImage+]" width="190" height="115"/></a>


    I started with the following PHx statement:
    [+phx:if=`[*introImage*]`:is=``:then=``:else=`<a href="[~[+id+]~]"><img class="floatLeft" src="[+introImage+]" alt="[+introImage+]" width="190" height="115"/></a>`+]


    But I’m guessing that the link and image HTML will remain if there is no image because the HTML is not part of the introImage TV - I guess I have to wrap the link and image HTML in something PHx can see?

    Not sure if this approach is even right, any suggestions would be much appreciated.

    Cheers

    Ben
      • 5532
      • 251 Posts
      I found a Ditto Request Extender called "stripTags" here: http://ditto.modxcms.com/files/assets/snippets/ditto/extenders/request-extender-inc-php.html#stripTags

      But it doesn’t provide any examples so not sure how you actually use it - does anyone have any ideas?

      Cheers
        • 5532
        • 251 Posts
        Not sure if I’m doing this right but it works.

        Here is the Ditto call I used:
        [!Ditto? &id=`news` &parents=`[*contentIDOne*]` &tpl=`newsHomeTpl` &showInMenuOnly=`1` &sortDir=`DESC` &paginate=`1` &display=`10` &paginateAlwaysShowLinks=`1` &tagData=`tags` &tagDelimiter=`,` &tagDocumentID=`55`!]


        Which used to reference this template:
        <div class="textBlock1 news">
        <a href="[~[+id+]~]"><h2>[+title+]</h2></a>
        <a href="[~[+id+]~]"><img class="floatLeft" src="[+introImage+]" alt="[+introImage+]" width="190" height="115"/></a>
        <p class="newsDetails">Posted on [*createdon:date=`%B %d %G`*]  |  Tags: [+tagLinks+]</p>
        <p>[+introtext+]</p>
        <p><a class="small green button" href="[~[+id+]~]" title="[+longtitle+]">View more »</a></p>
        </div>
        


        And here is an updated template with a PHx call replacing the [+introImage+] placeholder above:
        <div class="textBlock1 news">
        <a href="[~[+id+]~]"><h2>[+title+]</h2></a>
        [+phx:if=`[+introImage+]`:is=``:then=``:else=`<a href="[~[+id+]~]"><img class="floatLeft" src="[+introImage+]" alt="[+introImage+]" width="190" height="115"/></a>`+]
        <p class="newsDetails">Posted on [*createdon:date=`%B %d %G`*]  |  Tags: [+tagLinks+]</p>
        <p>[+introtext+]</p>
        <p><a class="small green button" href="[~[+id+]~]" title="[+longtitle+]">View more »</a></p>
        </div>


        I suspect I could’ve put the PHx call into the Ditto call but I couldn’t find any info on how to do - plus this seems to work, even on the tags page so I’ll just go with that.

        If anyone knows how to do this properly - sing out!
          • 36416
          • 589 Posts
          Quote from: cms at Jan 28, 2010, 12:30 PM

          I suspect I could’ve put the PHx call into the Ditto call but I couldn’t find any info on how to do - plus this seems to work, even on the tags page so I’ll just go with that.
          If anyone knows how to do this properly - sing out!

          Yeah, with full PHx plugin installed, I suggest:
          http://wiki.modxcms.com/index.php/PHx/CustomModifiers#phx:ifnotempty

          [+introImage:ifnotempty=`<a href="[~[+id+]~]"><img class="floatLeft" src="[+introImage+]" alt="[+pagetitle:htmlent+] intro" width="190" height="115"/></a>`+]
          
            • 5532
            • 251 Posts
            Thanks for the reply.

            So I’m guessing I’d use it in the Ditto template and that would become the [+introImage+] placeholder?
              • 36416
              • 589 Posts
              Quote from: cms at Jan 29, 2010, 03:59 AM

              So I’m guessing I’d use it in the Ditto template and that would become the [+introImage+] placeholder?

              Yes, but only if it’s not empty... tongue
                • 5532
                • 251 Posts
                Does anyone know if you can achieve this without having PHx installed? PHx and Jot are causing conflicts for me.

                Cheers

                Ben