We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21112
    • 156 Posts
    The web site I am developing uses ditto to present a variety of different resources, all stored as "articles" displayed by Ditto. I am using the Introtext field to give a summary of articles when listed by Ditto. Some of the articles are actually weblinks to external web sites. I would like for a summary to be displayed with these when called by Ditto also, so that users can get an idea of the link before they click on it. There is no Introtext field for weblink documents however.

    I have thought about putting the summary in the Description field, which seems the logical place for a weblink, but if I get Ditto to pull the string from the Description field for these, then the Descriptions, not the Introtext strings will be pulled for the other articles.

    My development philosophy is to always try and use features as they were intended to be used, so I don’t want to shove the summary for articles into the description field. I also don’t want to make things inefficient by using two templates to format the Ditto calls depending on their type. This also wouldn’t work for the "recent articles" list on the front page of the site, which I use to list the three most recently added articles, be they external links or internal pages.

    Does anyone have a good solution for this, or will I be forced to use one of the compromises I’ve mentioned above?
      • 21257 MODX Staff
      • 730 Posts
      I might be tempted to try constructing a conditional using the PHx snippet, right inside your template.
      If you look at the PHx documentation, it’s not too hard to construct a placeholder that essentially says
      " if Introtext is not empty, output Introtext, else output Description".
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 21112
        • 156 Posts
        Thanks for the tip! Sounds very promising! I’ll have a read about PHx and give it a try. If it works as you suggest, it might be useful to help me with an unrelated problem I’m having, so thanks in advance for both smiley
          • 21112
          • 156 Posts
          Unfortunately ganeshXL that wouldn’t work for my purposes, if I understand you correctly. The ditto call will always be displayed on a page with the doctype of document. The weblink that is being called may have a doctype of reference, but I don’t think the doctype is passed through the Ditto call is it?
            • 30765
            • 66 Posts
            We have the same issue, which we’re working around using PHx. I hadn’t thought of making a modifier though -- that’s a great idea.

            FWIW, here’s what we’re doing (this is in the context of a chunk used to create Atom feeds with Ditto):

            [+type:is=`reference`:then=`[+description+]`:else=`[+introtext+]`+]

            Pretty simple. But just keep in mind that by default the description field only allows 255 characters.

            Cheers
            Matt