@EVAL return $modx->runSnippet('Related', array("parents"=>"20"));
@EVAL return $modx->runSnippet('Related', array("parents"=>"40","tag"=>"Role","tagData"=>"21"));
@EVAL return $modx->runSnippet('Related', array("parents"=>"80"));@EVAL return $modx->runSnippet('Related', array("parents"=>"4");@EVAL return $modx->runSnippet('Related', array("parents"=>"4"));@EVAL return $modx->runSnippet('Related',array("parents"=>"80"));
@labasus
I recreated your structure and when I edit an ’item’ page I get a menu listing the category pages - and no error. So I’m somewhat puzzled. Do you think you could attach a screenshot of the error? Perhaps I’m missing something.
Thanks for pointing out those typos in the example text by the way, I’ve corrected the text.
Mark
# loop through and assemble a list
if (is_array($aFound) && count($aFound)>0) {
for ($i=0; $i<count($aFound); $i++) {
$aTagValues = explode(",",$aFound[$i][$tag]);
for ($j=0; $j<count($aTagValues); $j++) {
if ($aTagValues[$j] === $tagData || !$tagData) {
$fields = array('[+id+]','[+pagetitle+]','[+longtitle+]','[+introtext+]');
$values = array($aFound[$i]["id"],$aFound[$i]["pagetitle"],$aFound[$i]["longtitle"],$aFound[$i]["introtext"]);
$output .= str_replace($fields,$values,$rowTpl);
}
}
}
}
<?php return "option==value"; ?>
<?php /* Snippet name: Related Created by: Mark Croxton ([email protected]) Last modified: 16/06/2008 Version: 1.0.2 Description: Create one-to-many and many-to-many relationships between MODx documents in the manager Requires: Ditto 2.0+ and UltimateParent 1.0+ */ $output = ''; # grab the current doc id, even if we're inside the manager if(isset($_GET['id'])) { $id = intval($_GET['id']); } else if (isset($modx->documentIdentifier)) { $id = $modx->documentIdentifier; } else { $id = 0; } $parents = isset($parents)? $parents : 0; $sortBy = isset($sortBy)? $sortBy : "pagetitle"; // pagetitle || longtitle || ID $sortDir = isset($sortDir)? $sortDir : "ASC"; // ASC || DESC $depth = isset($depth)? $depth : 1; // Number of levels deep to retrieve documents $display = isset($display)? $display : "all"; // number of documents $rowTpl = isset($tpl)? $modx->getChunk($tpl) : '||[+pagetitle+]==[+id+]'; $tag = isset($tag)? "$tag" : ""; $topLevel = isset($topLevel)? "$topLevel" : 2; $noneOption = isset($noneOption)? "$noneOption" : 0; // show 'None' option by default $ultimateParent = $modx->runSnippet("UltimateParent", array("id"=>$id, "topLevel"=>$topLevel)); $inherit = isset($inherit)? "$inherit" : 0; // default: child documents with same template inherit selected parent's value $tagData = isset($tagData)? "$tagData" : 0; // default: use current doc id as tagged data if ($tagData === "ultimateParent") { $tagData=$ultimateParent; } else if ($tagData === "self") { $tagData=$id; } # either a new document with ultimateParent=1 where we can't determine tagdata since id is not yet saved # or a child document where we specifically want to inherit the parent value if (($ultimateParent != $id && $inherit) || (!$id && !$tagData)) { $output = 'INHERIT==@INHERIT'; return $output; } else { # grab data using Ditto $modx->runSnippet('Ditto', array( "parents" =>$parents, "depth" =>$depth, "display" =>$display, "sortBy" =>$sortBy, "sortDir" =>$sortDir, "save" =>"2", "tpl" =>"@CODE [+id+][+pagetitle+][+longtitle+][+introtext+][+".$tag."+]" ) ); $aFound = $modx->getPlaceholder("ditto_resource"); $fields = array('[+id+]','[+pagetitle+]','[+longtitle+]','[+introtext+]'); # loop through and assemble a list if (is_array($aFound) && count($aFound)>0) { for ($i=0; $i<count($aFound); $i++) { $aTagValues = array(); if ($tag !='') { $aTagValues = explode(",",$aFound[$i][$tag]); } if (count($aTagValues)>0) { for ($j=0; $j<count($aTagValues); $j++) { if ($aTagValues[$j] === $tagData) { $values = array($aFound[$i]["id"],$aFound[$i]["pagetitle"],$aFound[$i]["longtitle"],$aFound[$i]["introtext"]); $output .= str_replace($fields,$values,$rowTpl); } } } else { $values = array($aFound[$i]["id"],$aFound[$i]["pagetitle"],$aFound[$i]["longtitle"],$aFound[$i]["introtext"]); $output .= str_replace($fields,$values,$rowTpl); } } } # none option if ($noneOption) { $output = 'None==0'.$output; } else { $output = substr($output,2); } return $output; } ?>
<?php return include($modx->config['base_path'] . 'assets/snippets/related.php'); ?>