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

    I fairly new MODx user (one site, so far) and I starting to make my own snippets. Is there a right way? I guessing there is a "preferred" way smiley

    Here is my solution to get related documents based on a TV using Ditto.

    Is the following done properly? Did I really need a snippet to do it? Is there already a snippet that does this?
    [!Ditto? &startID=`35` &tpl=`speakerList` &sortBy=`pagetitle` &display=`all` &sortDir=`ASC` !]


    Chunk: speakerList
    		<div class="speaker">
    			<img src="[+headshot+]" alt="[+pagetitle+]">
    			<a href="[~[+id+]~]">[+pagetitle+]</a><br>
    			<p class="intro">[+introtext+]</p>
    			<div class="speaker_bio">
    				[+content+]
    			</div>
    			<div class="sessions">
    				<h3>My Sessions</h3>
    				[[getRelatedRecords? &parentFolder=`36` &ulClass=`links` &key=[+id+] &tv_match=`speaker`]]
    			</div>
    		</div>


    Snippet: getRelatedRecords
    <?php
    // usage
    // [!getRelatedRecords? &parentFolder=`36` &ulClass=`links` &key=[*id*] &tv_match=`speaker`!]
    
    $query_children = $modx->db->query('
    		SELECT contentid, pagetitle
    		FROM '.$modx->getFullTableName('site_tmplvar_contentvalues').'
    		LEFT JOIN '.$modx->getFullTableName('site_content').' 
    		ON '.$modx->getFullTableName('site_content').'.id = '.$modx->getFullTableName('site_tmplvar_contentvalues').'.contentid
    		WHERE `tmplvarid` = (SELECT id FROM '.$modx->getFullTableName('site_tmplvars').' WHERE name =  "'.$tv_match.'" LIMIT 1)
    		AND `value` = '.$key.'
    		');
    
    	    $relatedLinks = array();
    	    while ($row = $modx->db->getRow($query_children)) {
    		$relatedLinks[] = '<li><a href="index.php?id='.$row['contentid'].'">'.$row['pagetitle'].'</a></li>';
    	    }
    	    $output = implode("\n",$relatedLinks);
    	   return "<ul class=" . $ulClass . ">" . $output . "</ul>";
    ?>
      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
      • 7455
      • 2,204 Posts
      you could call a ditto inside a ditto template and the use the filter option I think,
      calling a ditto inside a ditto template does work I tried that part
        follow me on twitter: @dimmy01
        • 4385
        • 372 Posts
        Thanks Dimmy!

        I knew I was making it more difficult than it needed to be.
          DropboxUploader -- Upload files to a Dropbox account.
          DIG -- Dynamic Image Generator
          gus -- Google URL Shortener
          makeQR -- Uses google chart api to make QR codes.
          MODxTweeter -- Update your twitter status on publish.