We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31654
    • 238 Posts
    Hello I hope I can make some sort of sense...

    I’m creating a website for a record label. In MODx I have a folder (/releases/) and within this folder I have many pages each page represents a CD release.
    I have another folder (/artists/) and in this are many pages each one is dedicated to an artist/group.

    I’ve created a template for the releases which has TV’s: artistName, releaseTitle, releaseDate, etc.

    The artist pages use a generic template which doesn’t have any TV’s assigned to it.

    on the artists homepage (/artists/) I need to output a list of all the artists names linking to their individual pages (easy enough in Ditto or WayFinder) but below each artist name I want all the releases associated to them from the /releases/ folder (with a link to the release).

    I just can’t work out how to get Ditto to grab the TV’s from another template and then associate the releases to an artist in a list!.. Remember each artist has more than one release so I need to filter out duplicate artist/group names and associate all their releases to them in the list

    I hope this makes sense... I’m not a PHP coder at all so you’ll need to answer me in the most basic way possible!

    Many, many thanks for any help, I’m pulling my hair out here smiley

      Web Development, Web Hosting & Search Engine Marketing by:

      Vitalized | UK
      w. www.vitalized.co.uk

      Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

      Vitalized | Australia
      w. www.vitalized-australia.com.au

      Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
      • 4172
      • 5,888 Posts
      My Idea to get all the artist and releases together is first to create this snippet (maybe there are some bugs, but this is the idea)

      with this array we can go further and create output with parseChunk, runSnippet, setPlaceholder or direct outputloop.
      But first you can try this snippet, if you get the array what we need.
      In this example the pagetitles of your artistpages have to be the same as the TVvalues artistName in the releasepages

      <?php
      
      //[!GetMyArtists? &artistsParent=`foo` &releasesParent=`foo`!] 
      
      if (isset($artistsParent)&&isset($releasesParent)){
      $getTVs = array ('artistName','releaseTitle','releaseDate','pagetitle');
      $releases = $modx->getDocumentChildrenTVarOutput($releasesParent, $getTVs);
      
      $artistsarray = array();
      $releasesarray = array();
      
      
      if (count($releases)>0){
      	foreach ($releases as $key=>$release){
      		$release['releaseid']=$key;
      		$releasesarray[$release['artistName']][]=$release;
      	}
      }
      
      $artists = $modx->getDocumentChildren($artistsParent);
      if (count($artists)>0){
      	foreach ($artists as $artistfields){
      		$artist=array();
      		$artist['releases'] = $releasesarray[$artistfields['pagetitle']];
              $artist['pageid'] = $artistfields['id'];
      		$artistsarray[] = $artist;		
      	}
      }
      
      print_r($artistsarray);	
      	
      }
      
      ?>


      Bruno
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 31654
        • 238 Posts
        Wow, thanks for your quick reply!

        This is the output I get when I call:  [!GetMyArtists? &artistsParent=`19` &releasesParent=`30`!]

        [[EDIT - I changed the titles and assigned 3 artists to 5 releases]]

        Array ( [0] => Array ( [releases] => Array ( [0] => Array ( [releaseTitle] => Composition No. 3 [artistName] => Aardvark Jazz Orchestra [releaseDate] => 1975 [pagetitle] => Composition No. 3 by Aardvark Jazz Orchestra [releaseid] => 41 ) [1] => Array ( [releaseTitle] => Composition No. 1 [artistName] => Aardvark Jazz Orchestra [releaseDate] => 2005 [pagetitle] => Composition No. 1 by Aardvark Jazz Orchestra [releaseid] => 42 ) ) [pageid] => 47 ) [1] => Array ( [releases] => Array ( [0] => Array ( [releaseTitle] => Oyster Love [artistName] => Lapslap [releaseDate] => 2009 [pagetitle] => Oyster Love by Lapslap [releaseid] => 39 ) [1] => Array ( [releaseTitle] => Scratch by Lapslap [artistName] => Lapslap [releaseDate] => 2005 [pagetitle] => Scratch by Lapslap [releaseid] => 40 ) ) [pageid] => 46 ) [2] => Array ( [releases] => Array ( [0] => Array ( [releaseTitle] => Composition No. 2 [artistName] => Collective 4tet [releaseDate] => 1999 [pagetitle] => Composition No. 2 by Collective 4tet [releaseid] => 31 ) ) [pageid] => 48 ) )   
          Web Development, Web Hosting & Search Engine Marketing by:

          Vitalized | UK
          w. www.vitalized.co.uk

          Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

          Vitalized | Australia
          w. www.vitalized-australia.com.au

          Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
          • 31654
          • 238 Posts

          Would I be right in thinking
          $artist['releases'] = $releasesarray[$artistfields['pagetitle']];


          should be

          $artist['releases'] = $releasesarray[$artistfields['artistName']];


          I haven’t changed it yet, and I’m probably being stupid smiley

          Many thanks for all your help.
            Web Development, Web Hosting & Search Engine Marketing by:

            Vitalized | UK
            w. www.vitalized.co.uk

            Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

            Vitalized | Australia
            w. www.vitalized-australia.com.au

            Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
            • 4172
            • 5,888 Posts
            No its all ok, the array looks good. Are you planning to show all the datas on one page or do you need pagination or something like that.

            You could now run a loop to produce the output directly or modify the snippet a little so we can use the array for nested ditto-calls with the parameter &documents.

            I use allways my snippet Xett for this kind of work. An older release is somewhere in the forum under INDEVELOPEMENT, but it is not so easy to explain the first time how to use.

            So I think its better to try the nested Ditto-Solution.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 31654
              • 238 Posts
              Thank you so much for all your help.

              "Are you planning to show all the datas on one page or do you need pagination or something like that."
              I was going to use MooTools to paginate and use sortable columns but it would be good to have the option of pagination from Ditto.

              "You could now run a loop to produce the output directly or modify the snippet a little so we can use the array for nested ditto-calls with the parameter &documents."
              I must confess to not know what you mean, I’m really not a PHP programmer smiley

              I have other TV’s on the release template:
              $getTVs = array ('artistName','releaseTitle','releaseDate','pagetitle','releasePrice','releaseLabel','releaseCover','catalogueNo');
              


              How can I template the output?

              Many, many thanks for your help it’s very kind of you.

              Si

                Web Development, Web Hosting & Search Engine Marketing by:

                Vitalized | UK
                w. www.vitalized.co.uk

                Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

                Vitalized | Australia
                w. www.vitalized-australia.com.au

                Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
                • 4172
                • 5,888 Posts
                Here is the way you can go with nested Ditto-calls:

                snippet GetMyArtists:
                <?php
                //the call to create the placeholder before your ditto call
                //[!GetMyArtists? &artistsParent=`foo` &releasesParents=`foo1,foo2,foo3`!] 
                
                //the call in your ditto-tpl to get the artist-releases
                //[[GetMyArtists? &id=`[+id+]`]] 
                
                
                if (isset($id)){
                
                $artistsarray=$modx->getPlaceholder('artistsarray');
                
                $params=array();
                //here come all your parameters for the nested ditto-call:
                $params['display']='all';
                $params['tpl']='DittoArtistReleasesTpl';
                $params['documents']=$artistsarray[$id];
                return $modx->runSnippet('Ditto',$params); 	
                	
                }
                
                if (isset($artistsParent)&&isset($releasesParents)){
                $getTVs = array ('artistName');
                $artistsarray = array();
                $releasesarray = array();
                
                $parents=explode(',',$releasesParents);
                foreach($parents as $releasesParent){
                $releases = $modx->getDocumentChildrenTVarOutput($releasesParent, $getTVs);
                if (count($releases)>0){
                	foreach ($releases as $key=>$release){
                		//$release['releaseid']=$key;
                		$releasesarray[$release['artistName']][]=$key;
                	}
                }	
                }
                
                $artists = $modx->getDocumentChildren($artistsParent);
                if (count($artists)>0){
                	foreach ($artists as $artistfields){
                		//$artist=array();
                		//$artist['releases'] = implode(',',$releasesarray[$artistfields['pagetitle']]);
                        //$artist['pageid'] = $artistfields['id'];
                		$artistsarray[$artistfields['id']] = (isset($releasesarray[$artistfields['pagetitle']]))?implode(',',$releasesarray[$artistfields['pagetitle']]):'';				
                	}
                }
                
                //print_r($artistsarray);	
                
                $modx->setPlaceholder('artistsarray',$artistsarray);
                	
                }
                
                ?>


                on your artists parent-page:
                [!GetMyArtists? &artistsParent=`[*id*]` &releasesParents=`1000,2000,3000,4000`!]
                [!Ditto? &tpl=`DittoArtistListTpl`&display=`all`!]


                chunk DittoArtistListTpl for example:
                <h3><a href=[+id+]>[+pagetitle+]</a></h3>
                <ul>
                [[GetMyArtists? &id=`[+id+]`]]
                </ul>


                chunk DittoArtistReleasesTpl for example:
                <li>
                <h4><a href=[+id+]>[+pagetitle+]</a></h4>
                <ul>
                <li>[+releaseTitle+]</li>
                <li>[+releaseDate+]</li>
                <li>[+releasePrice+]</li>
                <li>[+releaseLabel+]</li>
                <li>[+releaseCover+]</li>
                <li>[+catalogueNo+]</li>
                </ul>
                </li>
                


                I did a short test and it seems to work

                Bruno
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 31654
                  • 238 Posts
                  Thanks again for your help...

                  I don’t quite understand your instructions... The way I’ve set it up is:

                  Chunk called: DittoArtistListTpl
                  <h4><a href=[+id+]>[+pagetitle+]</a></h4>
                  <ul>
                  <li>[+releaseTitle+]</li>
                  <li>[+releaseDate+]</li>
                  <li>[+releasePrice+]</li>
                  <li>[+releaseLabel+]</li>
                  <li>[+releaseCover+]</li>
                  <li>[+catalogueNo+]</li>
                  </ul>
                  


                  Snipet calls on my Artists Home Page:
                  [!GetMyArtists? &artistsParent=`19` &releasesParent=`30`!]
                  [!Ditto? &tpl=`DittoArtistListTpl`&display=`all`!]

                  Which gives me this output:
                  <h4><a href=48>Collective 4tet</a></h4>
                  
                  <ul>
                  <li></li>
                  <li></li>
                  <li>11.00</li>
                  <li>Leo Records</li>
                  <li></li>
                  <li></li>
                  </ul><h4><a href=47>Aardvark Jazz Orchestra</a></h4>
                  <ul>
                  <li></li>
                  <li></li>
                  <li>11.00</li>
                  <li>Leo Records</li>
                  
                  <li></li>
                  <li></li>
                  </ul><h4><a href=46>Lapslap</a></h4>
                  <ul>
                  <li></li>
                  <li></li>
                  <li>11.00</li>
                  <li>Leo Records</li>
                  <li></li>
                  <li></li>
                  </ul>
                  


                  I also tried the this as the Chunk
                  <h3><a href=[+id+]>[+pagetitle+]</a></h3>
                  <ul>
                  [[GetMyArtists? &id=`[+id+]`]]
                  </ul>


                  But that gave me an error message:
                  &tpl either does not contain any placeholders or is an invalid chunk name, code block, or filename. Please check it.

                  I’m sure I’m missing something really obvious!... Can the script also handle multiple ID’s for the releases?
                  The release catalogue has four record labels so I’m creating four sub-folders in the ’Catalogue’ directory.

                  I really can’t thank you enough for all your help smiley
                    Web Development, Web Hosting & Search Engine Marketing by:

                    Vitalized | UK
                    w. www.vitalized.co.uk

                    Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

                    Vitalized | Australia
                    w. www.vitalized-australia.com.au

                    Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
                    • 4172
                    • 5,888 Posts
                    Have changed the code above a little again for multiple releasepages and changed the parameter &releasesParent to &releasesParents

                    Don’t forget to modify this part of the inner Ditto-Call to your needs:
                    //here come all your parameters for the nested ditto-call:
                    $params['display']='all';//Ditto-Parameter &display
                    $params['tpl']='DittoArtistReleasesTpl';//Ditto-Parameter &tpl
                    $params['documents']=$artistsarray[$id];
                    return $modx->runSnippet('Ditto',$params);


                    you need two different chunks.
                    One for the outer Ditto-Call: DittoArtistListTpl
                    One for the inner Ditto-Call (which ist called with modx->runSnippet): DittoArtistReleasesTpl
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 4172
                      • 5,888 Posts
                      And here is a much easier solution without the need of extra snippet:

                      chunk DittoArtistListTpl:
                      <h3><a href=[+id+]>[+pagetitle+]</a></h3>
                      <ul>
                      [[Ditto? &parents=`1000,2000,3000` &filter=`artistName,[+pagetitle+],1`&tpl=`DittoArtistReleasesTpl`]]
                      </ul>
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!