We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16429
    • 254 Posts
    I’ve a page structure like this

    Products
    |
    - Brand1
    |
    - Product1.a
    - Product1.b
    - Product1.c
    - Brand2
    |
    - Product2.a
    - Product2.b
    - Product2.c

    etc etc.
    I need Ditto to list Brands if Products matches some normal filter (a tv value).
    In fact this is yet possible, but it will list the Brand once for every Product matching the filter instead of listing them once at all if one or more Products match.

    How can I achieve this?
      kudo
      www.kudolink.com - webdesign (surprised?)

      [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
      • 18397
      • 3,250 Posts
      You could create a set of Ditto templates to create a comma delimited list and then pass that on to another Ditto call to generate the list of Brands.

      &tpl would be [+parent+] space comma

      &tplLast would be [+parent+]
        • 16429
        • 254 Posts
        Thanks for the reply but this time I didn’t understand what you mean smiley
          kudo
          www.kudolink.com - webdesign (surprised?)

          [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
          • 18397
          • 3,250 Posts
          Create two chunks

          mainDittoTemplate with the content [+parent+] space comma
          endDittoTemplate with the content [+parent+]

          Then call Ditto like so [!Ditto &startID=`[[Ditto &startID=`#` &tpl=`mainDittoTemplate ` &tplLast=`endDittoTemplate`]]` !]

          Its a recursive Ditto call! wink
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Don’t you need a ? after the Ditto in those calls? (Ditto? &...)
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 18397
              • 3,250 Posts
              Yes, thank you for the correction Susan.
                • 16429
                • 254 Posts
                Ok, now coming back to this discussion... smiley

                From the first Ditto call I obtain the parents ids.
                Let’s say "10, 14, 21". Well, the output is more like "10, 10, 10, 10, 10, 14, 14, 14, 21, 21, 21, 21".

                Now I’ve another surrounding Ditto call... but this Ditto call gets me the children of those IDs.
                Is there a way to tell Ditto those actually are the documents to retrieve?

                Perhaps with the help of the "&documents=" param?

                  kudo
                  www.kudolink.com - webdesign (surprised?)

                  [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
                  • 18397
                  • 3,250 Posts
                  Exactly, Ditto should only retrieve one of each document.
                    • 16429
                    • 254 Posts
                    I think I’m getting tedious with this thread...

                    If I use &documents there’s an error in the SQL query: basically if I use &documents there are no IDs in the WHERE statement.

                    After looking at the function parseSeedIDs I think I’ve found an error, maybe left from previous coding.
                    In ditto.class.inc.php, at line 402 you find:
                    			$kids = explode(',',$seedArray);
                    

                    But $seedArray is called only here, doesn’t exist nor has a value.
                    After reading the code flow I’ve tried replacing it with $ids and it works!
                    			$kids = explode(',',$ids);
                    

                    The query error has disappared and the documents I want are shining in my page smiley

                    MUHauhauhauaUAHuahuhaUAHua grin
                    It lives, IT LIVES!!

                    Sorry, but I’m too much happy laugh
                      kudo
                      www.kudolink.com - webdesign (surprised?)

                      [img]http://www.kudolink.com/kudolinkcom.png[/img] [sup]proudly uses[/sup] [img]http://www.kudolink.com/modx.png[/img]
                      • 18397
                      • 3,250 Posts
                      Here is the version from 1.1 Beta 3 which should fix the problem as well :

                      	function parseSeedIDs($ids, $idType,$descendentDepth) {
                      		$seeds = explode(',', $ids);
                      		if ($idType == "parents") {
                      			$kids = array();
                      			foreach ($seeds AS $seed) {
                      				if ($descendentDepth > 1) {
                      					$kids = $this->functions->getParentIds($seed, $descendentDepth, $kids);
                      				}else{
                      					$kids[] = $seed;
                      				}
                      			}
                      		} else if ($idType == "documents") {
                      			$kids = $seeds;
                      			$this->callback = 'getDocumentsMODx';
                      		}
                      
                      		return $kids;
                      	}