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
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>";
?>