We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33982 ☆ A M B ☆
    • 476 Posts
    I’m using MODx 0.9.6 with Ditto version 2.0.2 and PHx version 2.1.2

    Here’s what I’m trying to accomplish. I’m trying to make it so that on a site I can modify the TPL’s for the ditto. So depending on the children of the parent, there will be a different output in the TPL that ditto uses. In my case, I’ve got a page that has endorsements for a Congressional Candidate. Some endorsements will include pictures, others will not. So I’m trying to make it so that if the endorsement doesn’t have an image, a different TPL will be used. Here’s the logic I’m using:

    Here is the ditto call of the parent:

    [[Ditto? &startID=`55` &tpl=`endorsementTPL` &summarize=`50` &sortDir=`DESC` &sortBy=`pub_date` &depth=`1` ]]
    


    But as I mentioned above, some endorsements don’t have a picture. So I created a chunk named "endorsementTPL" with the following code:

    [+endorsementswitch:is=`0`:then=`{{endorsementpicNOTPL}}`:else=`{{endorsementpicTPL}}`+]
    


    As you can see I’m using PHx to try and modify which TPL will be chosen. The customer choses in the document’s T.V. whether there is an endorsement or not. If so, they get "{{endorsementpicTPL}}" which has:

    <div id="endorsementsbox">
    <img id="endorsementsboximg" src="[+endorsementimg+]" alt="Mike Lumpkin Endorsement" />
    <div id="endorsementstext">
    <textile>
    
    [+introtext+] <a href="[+id+]">read more</a>...
    
    </textile>
    <div id="endorsementsname">
    <p>[+longtitle+]</p>
    </div><!--Endorsments Name-->
    </div><!--Endorsements Text-->
    </div><!--Endorsements Box-->
    


    If no picture, they choose "{{endorsementpicNOTPL}}" which has:

    <div id="endorsementsboxnoPic">
    <div id="endorsementstextnoPic">
    <textile>
    
    [+introtext+] <a href="[+id+]">read more</a>...
    
    </textile>
    <div id="endorsementsname">
    <p>[+longtitle+]</p>
    </div><!--Endorsments Name-->
    </div><!--Endorsements Text-->
    </div><!--Endorsements Box-->
    


    Here’s the problem that I’m having.

    On the parent document, there will be the output for that particular TPL (background images and such), but the values for the T.V.’s are not showing up. In other words, [+longtitle+], [+introtext+], [+endorsementimg+] are not producing an output. I’ve tried changing them to [*longtitle*], [*tvlongtitle*], [+tvlongtitle+] For example, the output for the endorsement box with a picture is shown here:

    <div id="endorsementsbox">
    <img id="endorsementsboximg" src="" alt="Mike Lumpkin Endorsement" />
    <div id="endorsementstext">
    <p> <a href="85">read more</a>...</p>
    <div id="endorsementsname">
    <p></p>
    </div><!--Endorsments Name-->
    </div><!--Endorsements Text-->
    </div><!--Endorsements Box-->
    


    Am I approaching this problem the wrong way? Is there an easier way to modify which TPL the ditto will use for a particular child document?

    Any insight will be greatly appreciated...thanks!
      Precision Web Development ... SmashStack.com
      • 21257 MODX Staff
      • 730 Posts
      I think Ditto just wants the name of the Chunk, and in your PHx logic, you’re actually returning the contents of the Chunk.
      I’d try changing endorsementsTPL to:
      [+endorsementswitch:is=`0`:then=`endorsementpicNOTPL`:else=`endorsementpicTPL`+]
      


      I also wonder if you could just use that PHx logic right in the snippet call, instead of having a chunk do it for you.

      [[Ditto? &startID=`55` &tpl=`[+endorsementswitch:is=`0`:then=`endorsementpicNOTPL`:else=`endorsementpicTPL`+]` &summarize=`50` &sortDir=`DESC` &sortBy=`pub_date` &depth=`1` ]]
      


      Just an idea.. not promising anything ;-)
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 33982 ☆ A M B ☆
        • 476 Posts
        Thanks netProphET for your input...unfortunately, neither one of those work. But thanks for responding!
          Precision Web Development ... SmashStack.com
          • 21257 MODX Staff
          • 730 Posts
          Oops :’(
          One last idea - I have seen PHx cause some problems parsing tags within tags.
          What if you set up your TV called endorsementswitch so that it’s actual value is either
          endorsementpicNOTPL
          or
          endorsementpicTPL
          .. instead of 0 and whatever.
          Then just replace the chunk call or PHx modifier in the Ditto call with [+endorsementswitch+]
          But if PHx decides to grab up the value of endorsementswitch before it makes it to the Ditto call, I’m afraid it won’t work.
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 6726
            • 7,075 Posts
            I don’t think it’s a nested call issue here. I have similar logic working for me.
            I think the problem is you should use the if statement (I am not aware that you can skip it...) :

            If in the context of a Ditto template :

            [+phx:if=`[+endorsementswitch+]`:is=`0`:then=`{{endorsementpicNOTPL}}`:else=`{{endorsementpicTPL}}`+]


            If directly in the context of the page :

            [+phx:if=`[*endorsementswitch*]`:is=`0`:then=`{{endorsementpicNOTPL}}`:else=`{{endorsementpicTPL}}`+]
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l&#39;outil id
              • 33982 ☆ A M B ☆
              • 476 Posts
              Thank you David Molliere for replying.

              I’m sorry, but I don’t think I clarified the problem too well above that I’m having...or maybe I put too much info. grin

              The problem is not that PHx isn’t working (it is working just fine), but the T.V.’s are not outputting their values. For example, I have background images and some text that’s associated with each TPL that are not T.V. specific and they’re showing up just fine. But the output for the T.V.’s of both PHx selections themselves are empty.

              I hope that makes sense...

              Thanks again for your reply.

              Am I approaching this problem the wrong way? Is there an easier way to modify which TPL the ditto will use for a particular child document?
                Precision Web Development ... SmashStack.com
                • 29635
                • 361 Posts
                I think what David said makes sense. You’re running PHx based on the values of the *current* page, not the page Ditto is accessing. I realize you don’t think that’s your problem, but it definitely seems like a bad idea to me.

                I’ve done stuff like this in the past, and I generally end up doing all the logic inside a single chunk. So tpl=`my_chunk`, where {{my_chunk}} has the PHx logic. You can also avoid the extra TV for the switch.

                Just something like [+phx:if=`endorsementimg`:ne=``:then=`
                blah blah blah
                `:else=`
                other blah blah
                `+]

                Don’t quote me on that syntax, but that’s the idea. Stick both chunks into a single chunk and keep the logic there.
                  Need MODx Ecommerce? Try FoxyCart!
                  • 33982 ☆ A M B ☆
                  • 476 Posts
                  Hey Brett,

                  Thanks for the reply, but again your solution is yielding the same problem. Is there any easy was to just change the tpl for the ditto’s children...the tpl can change for a particular factor (in this case when there is and is not a picture)?

                  Thanks!
                    Precision Web Development ... SmashStack.com
                    • 6726
                    • 7,075 Posts
                    Hey flinx, you can just stick to David wink

                    Well, indeed I thought this was not working at all... I am not sure I understand what you’re trying to do.
                    As Brett said, I am not sure PHx is built to handle the logic the way you’re trying to.
                    Then again PHx is so powerful I wouldn’t bet on it tongue

                    Maybe try to get Armand (bS, who wrote PHx) to give you some hints !
                      .: COO - Commerce Guys - Community Driven Innovation :.


                      MODx est l&#39;outil id