We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12844
    • 59 Posts
    Hello all,

    I have a chunk which is used as a Ditto template:

    <dt>[+pagetitle+], <a rel="external" href="[+authorurl+]">[+description+]</a></dt>
    <dd><blockquote>[+content+]</blockquote></dd>

    The parts in red I would like only to appear if my authorurl template variable has a value.

    How do I go about making this the case? I think I need to use a snippet, but feel like I need some guidance. Many thanks.
      • 16183
      • 1,390 Posts
        • 12844
        • 59 Posts
        Thanks for the pointers. I’m trying the PHx route as it seems that could be useful to know about in future.

        My Ditto call:

        [!Ditto? &parents=`6` &depth=`1` &tpl=`testimonial` &sortDir=`ASC` !]


        ’testimonial’ chunk (my Ditto template):

        <dt>[+pagetitle+], [+phx:if=`[*authorurl*]`:isnot=``:then=`{{testimonialauthorwithlink}}`:else=`{{testimonialauthorwithoutlink}}`+]</dt>
        <dd><blockquote>[+content+]</blockquote></dd>


        [*authorurl*] is a template variable (url) which may or may not have a value.

        {{testimonialauthorwithlink}} chunk:
        <a href="[*authorurl*]">[+description+]</a>


        {{testimonialauthorwithoutlink}} chunk:
        [*authorurl*]


        However, I’m not getting anything appearing, whether or not the authorurl template variable has a value.

        Can anyone see where I may be going wrong?
          • 12844
          • 59 Posts
          Not sure what to try next, so if anyone can suggest something I’d appreciate it - thanks.
            • 16183
            • 1,390 Posts
            David,

            I’ve tested your code and it works fine except for two things:

            1. The TV value returned is not the individual children documents’ but the parent document’s - so, using your example ditto call, the parent’s (document 6) TV value is returned for all the displayed documents. I suppose you want the children documents’ TV value returned.

            By the way, why do you need the chunk {{testimonialauthorwithoutlink}}? I ask since if the TV is empty, there’s no url so why display [*authorurl*]?

            2. [+description+] - does not return anything even when the field is not empty

            Now, I have never used ditto so I know just very basic stuff about and don’t know about the [+description+]

            What version of Ditto are you using? There’s a version from which PHx comes with Ditto so no need for a separate install. I’ll let the gurus weigh in on this...

            cheers/k
              • 16278
              • 928 Posts
              IANAG, but I think PHx can be applied to what was stated in the original post quite simply:
              [+authorurl:isnot=``:then=`<a rel="external" href="[+authorurl+]">[+description+]</a>`+] 
              I view the "phx" pseudo-placeholder as a last resort.

              rolleyes [+description+] works for me in a Ditto template chunk - reproduces the Description field of the document in question.
              cool KP
              More on Ditto & PHx at http://www.pogwatch.com/ditto/ditto-phx.html
                • 16183
                • 1,390 Posts
                @kp

                Thanks for the insight. Not only wasn’t [+description+] not working but I kept getting parse errors on the front end ..something about prePHx not found in one of the ditto files.

                Tried your code and it worked a treat - the correct TV values are output plus the {+description+]. Brilliant! David will be happy smiley

                cheers/k

                EDIT: Getting the errors again:

                Fatal error: Class ’prePHx’ not found in C:\wamp\www\modxtests\assets\snippets\ditto\classes\ditto.class.inc.php on line 329

                It’s not important to me since was testing this for David but an answer to this issue might help someone else. Thanks
                  • 12844
                  • 59 Posts
                  Thanks a lot guys - it’s working fine, and I’m sure I’ll use this method again and again in future. Here’s what I have now:

                  [+authorurl:isnot=``:then=`<a rel="external" href="[+authorurl+]">[+description+]</a>`:else=`[+description+]`+]


                  Quote from: kongondo at Jun 06, 2009, 07:03 PM

                  By the way, why do you need the chunk {{testimonialauthorwithoutlink}}? I ask since if the TV is empty, there’s no url so why display [*authorurl*]?

                  There will always be a testimonial author assigned to the entry, but not always a url. {{testimonialauthorwithoutlink}} was just `[*authorurl*]`, and in writing this reply I’ve just realised that it should have been `[*description*]` instead (which provided the author). I could’ve just put `[*description*]` straight in without using another chunk.

                  Thanks again for the great help.