We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22586
    • 74 Posts
    Time to give back to the community smiley

    The scope : If you want to ditto only a child folder with a specific name of a document, you can use this technique. I used this because I had documents with different child folders (containers) Each container had a static name. One of them was linkfolder, and this is just a folder with lots of weblinks in them. Now I only wanted to ditto those, and not the content of the other child-folders.

    So first you have this ditto call :
    [!Ditto? &filter=`parent,[[getChildofLinkfolder]],1` &depth=`2` &hideFolders=`1` &tpl=`links_output` &noResults=` ` &display=`3`!]

    &filter : this does the magic. It gets the parent of the folder, this would be your current document (you must think from the child folder perspective here), and the getChildofLinkfolder will return only documents from the folder that has as the parent the current document.

    &noResults : I wanted to omit the no documents found message.

    &hideFolders : Is -Off- so you ditto doesn’t show the folders themselves, only the content.

    --
    Now the snippet [[getChildofLinkfolder]] :
    <?php
    
    $id = $modx->documentObject['id'];
    $children = $modx->getDocumentChildren($id, '1', '0', 'id,pagetitle');
    
    // Initialize the output
    $output = '';
    
    foreach ($children as $child) {
        // Get the children and check for a specific folder name
       if ($child['pagetitle'] == "linkfolder") {
       $output .= $child['id'] . ',';
       };
       }
    
    $output = rtrim($output, ',');
    return $output;
    ?>


    This is fairly straightforward, just remember to insert the name of the folder you want to data to return from instead of "linkfolder"

    I hope its useful, depending on how useful this is this can be movied to a more permanent documentation area. I am fairly new to ModX , so if there is a more seasoned expert, I’d love to hear feedback.