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

    I’ve managed to create a three tier site structure which populates a jquery accordion. My structure looks as follows:

    Parent (DITTO - This has the first ditto call in, which then retrieves the adjacent children)
    ----------> Article 1 (DITTO - This is the second ditto call which pulls the Grandchildren)
    Article 2
    Article 3
    Article 4
    ----------> SubArticle 1
    SubArticle 2
    SubArticle 3
    SubArticle 4

    I can get this to work, but my problem lies with the second Ditto Call.. At the moment the &startID is hardcoded but I need this to be dynamic so that each Article header i click on then displays the Subarticles. At the moment, no matter which Article I select it’s pulling the same SubArticlesn.. This is because as mentioned above the ditto call is using a hardcoded page id. I have tried using [+id+] and [+parent+] etc as the startId in the ditto call but the ditto call thinks its on the top level as the accordion is created on the parent page template.

    is there anyway I can get the subarticles of a given Article page id instead so that it will pull the correct group of subarticles?

    My current Ditto call for the 2nd tier is as follows:

    [[Ditto? &parents=`1228` &orderBy=`createdon DESC` &tpl=`schemes_list_template` &hiddenfields=`schemethumb`]]

    I need the &parents id to be dynamic...

    any idea how I’d do this?
      • 33337
      • 3,975 Posts
      Use &parents=`[*id*]`
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 22472
        • 3 Posts
        I have tried this... but it grabs the value of the parent id as the accordion is all implemented on the parent page... the 2nd ditto call even though it’s on a different tier, technically its not as its all being called from the same page..

        If anything I need the Article ID and not the Parent ID

        Does that make sense?

          • 33337
          • 3,975 Posts
          May be you need to think about using Wayfinder?

          Because you are going for children and grand children docs, its like a sub navigation. Wayfinder is flexible in this kind of templating.
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 15022
            • 31 Posts
            Hello,
            I’m not entirely clear about the structure of your Ditto calls but it looks like you need to create the Ditto call for the second tier inside the tpl you use for the first tier and use &parents=`[+id+]` .. in other words "nest" them.
            Just make sure you alternate your Ditto calls between cached and uncached. So if level 1 call is uncached, call the level 2 Ditto as cached.
            I understand why you don’t want to use Wayfinder for this.. it is difficult to get the markup you need. Use nested Ditto calls.
            I can give you more specific code if you put your complete Ditto calls and tpl here. Let us know if this solves things for you.
              illegitimati non carborundum
              • 22472
              • 3 Posts
              Hi Both,

              Thank you for helping,

              My original Ditto Call on the parent page template is:

              [[Ditto? &parents=`1036` &orderBy=`createdon DESC` &tpl=`schemes_dropdown`]]

              The second ditto call which is in the schemes_dropdown template is as follows:

              [[Ditto? &parents=`1228` &orderBy=`createdon DESC` &tpl=`schemes_list_template` &hiddenfields=`schemethumb`]]

              As you can see in the second ditto call &parents is currently set to 1228, that needs to be something which will grab the id of the Article page... which would be the sibling of the parent page...

              any help would be great..

              Thank you
                • 26931
                • 2,314 Posts
                &parents=`1228` ... that needs to be something which will grab the id of the Article page... which would be the sibling of the parent page...
                -> &parents=`[+id+]` in the nested Ditto Call?
                  • 1122
                  • 209 Posts
                  Displaying multilevel structure with Ditto is easy doable with the use of recursion (on several occasions on this forum I provided similar solutions). Here it goes one more time, you can adjust it to fit your needs.

                  Suppose, we need to display with a single Ditto call the document map for entire site (a kind of poor replacement for Wayfinder):
                  [[Ditto? &parents=`0` &depth=`1` &display=`all` &tpl=`one-level` &orderBy=`menuindex ASC`]]
                  

                  The above will display first (highest) level of documents, but with an appropriate content of "one-level" chunk we can cause displaying all remaining levels:
                  <!-- content of "one-level" chunk -->
                  <div style="margin: 0 0 0 20px;">
                      <!-- this part displays current level of the documents -->
                      <p><a href="[~[+id+]~]">[+pagetitle+]</a></p>
                      <!-- this part recursively displays one level deeper - children of the document being processed above -->
                      [[Ditto? &parents=`[+id+]` &depth=`1` display=`all` &tpl=`one-level` &noResults=`empty` &orderBy=`menuindex ASC`]]
                  </div>
                  

                  Nested Ditto call still uses "one-level" chunk for rendering documents, so it will be replicated as many times as many levels you have in your site tree (in practice, this self-replication is limited to 10 -- the default maximum for MODx parser’s passes).

                  The important detail is &noResults=`empty` used for rendering when Ditto (going deeper) reaches document having no children (leaf). I use for this purpose something like this:
                  <!-- content of "empty" chunk -->
                  [+non-existent-var+]
                  

                  TV "non-existent-var" -- as unresolved placeholder -- will be replaced with empty text.

                  Also please notice that children will be wrapped with nested div-containers that will indent each consecutive level of documents with 20 pixels more.