We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24278
    • 165 Posts
    Using ditto 2.0.1how can I create a link to the parent of the document, in the ditto listing e.g. ...

    Document name: The great escape
    Parent folder: Movies

    Document name: DaVinci Code
    Parent Folder: Books

    sample ditto listing...

    The great escape published in Movies
    DaVinci Code published in Books


      • 25663 MODX Staff
      • 12,272 Posts
      Use a template that uses [+pagetitle+] and [+parent+] ... not sure about the parent link bit tho...
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 17883
        • 1,039 Posts
        I think this could be done with a TV for every page and this snippet.

        First create a simple TV (text) "parenttitle" for the single documents and put in "[!getField?field=`pagetitle` &id=`[*id*]` &parent=`1` !] as standard value.

        Then call this TV in your ditto template with [+parenttitle+] (ditto2.0) or [+tvparenttitle+] (< ditto2.0). For the link to the corresponding section do the same with the id as field (or simple [~[+parent+]~] in the ditto template).

        Not tested, but I think should work like this (not sure about the filed names).
          • 18397
          • 3,250 Posts
          You don’t need to wrap the getField call in a tv. You should be able to just put:

          [!getField?field=`pagetitle`&id=`[+parent+]`!]
          


          This should work as a link: [~[+parent+]~]
            • 11975
            • 2,542 Posts
            Hi,

            the getField snippet is handy but if you have a huge amount of documents and to avoid a huge increase of db queries, you should tweak the getfield code a little bit to use placeholders ($modx->setPlaceholder() ) to store the value.

            :-)
              Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
              • 11975
              • 2,542 Posts
              I’ve not tested it but it could work

              :-)


              <?php
              
              /*
              
              Execute getField from ditto and store the value in modx placeholders
              
              */
              
              $parentID = (isset($parentID) ) ? $parentID : return false;
              
              $phName = (isset($phName)) ? $phName: "ditto_parent_title";
              $field = (isset($field)) ? $field: "pagetitle";
              $snippetName = (isset($snippetName)) ? $snippetName: "getField";
              $dittoID = (isset($dittoID)) ? $dittoID : '';
              
              
              
              $ph_value = $modx->getPlaceholder($dittoID . $phName . $parentID);
              
              if(isset($ph_value)){
              
              $parentField = $ph_value;
              
              }else{
              
              $params['id'] = $parentID;
              $params['field'] = $field;
              
              $parentField = $modx->runSnippet($snippetName,$params);
              $modx->setPlaceholder($dittoID . $phName . $parentID, $parentField);
              
              }
              
              return $parentField;
              
              
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 8960
                • 150 Posts
                Quote from: Mark at Mar 20, 2007, 03:06 PM

                [!getField?field=`pagetitle`&id=`[+parent+]`!]
                


                This should work as a link: [~[+parent+]~]

                Using this call only returned the pagetitle of the document this call is in (and the linking didn’t work).

                This call returned the pagetitle of the parent document (getField does pagetitle by default), but I need to know now how to make a link, or rather, if I use UltimateParent, how to make it link to just the parent and not the ultimate parent:

                <a href="[~[[UltimateParent]]~]">[!getField? &parent=`1` &parentLevel=`1`!]</a>


                Note: I used UltimateParent to link because I didn’t know a better way.
                  • 18397
                  • 3,250 Posts
                  <a href="[~[+parent+]~]">[!getField?field=`pagetitle`&id=`[+parent+]`!]</a>
                    • 11975
                    • 2,542 Posts
                    Here is a new version of the code posted above

                    it should work for any snippet call within a ditto tpl

                    here are some test results
                    With 198 documents
                    Ditto call

                    [!ditto? &parents=`0` &tpl=`photolist` &summarize=`198` &depth=`4` &paginate=`1` &limit=`200` &filter=`isfolder,1,2` !]

                    with
                    [[GetField? &id=`[+parent+]` &field=`pagetitle` ]]

                    MySQL: 1.6104 s, 413 request(s)

                    with
                    [[SSR? &ph_ID=`[+parent+]` &phName=`ditto_parent_name` &snippetName=`GetField` &snippetParams=`docid:[+parent+]|field:pagetitle` ]]
                    MySQL: 1.6374 s, 216 request(s)

                    SSR code

                    <?php
                    
                    
                    /*
                    
                    
                    SSR : StoreSnippetResult
                    
                    Author : heliotrope
                    
                    Description:
                    Execute snippet from ditto and store the value in modx placeholders
                    Reduce the amount of db queries
                    
                    Sample call for getField
                    [[GetField? &id=`[+parent+]` &field=`pagetitle` ]]
                    becomes
                    [[SSR? &ph_ID=`[+parent+]` &phName=`ditto_parent_name` &snippetName=`GetField` &snippetParams=`id:[+parent+]|field:pagetitle` ]]
                    
                    
                    */
                    
                    
                    $ph_ID = (isset($ph_ID) ) ? $ph_ID : false;
                    $phName = (isset($phName)) ? $phName: "SSR_";
                    $sName = (isset($sName)) ? $sName: false;
                    $ditto_ID = (isset($dittoID)) ? $ditto_ID : '';
                    
                    //snippetParams=`id:id_value|field:field_value`
                    $snippetParams = (isset($snippetParams)) ? $snippetParams : false ;
                    
                    
                    if(!$ph_ID) return "Missing ph_ID";
                    if(!$sName) return "Missing Snippet Name";
                    if(!$snippetParams) return "Missing Snippet Params";
                    
                    $modxPH = $dittoID . $phName . $ph_ID;
                    $ph_value = $modx->getPlaceholder($modxPH);
                    
                    if(isset($ph_value)){
                    
                    	$s_output = $ph_value;
                    
                    }else{
                    
                    	$gParams = explode('|', $snippetParams);
                    	$sParams = array();
                    
                    	foreach($gParams as $params){
                    	
                    		$paramV = explode(':',$params);
                    		$sParams[$paramV[0]] = $paramV[1];
                    	}
                    
                    	$s_output = $modx->runSnippet($sName,$sParams);
                    	$modx->setPlaceholder($modxPH, $s_output);
                    
                    }
                    
                    return $s_output;
                    
                    
                    
                    
                    
                    ?>
                    
                      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                      • 8960
                      • 150 Posts
                      Mark, thanks for posting that. I think where that isn’t working for me is I’m not using this call within Ditto. So I think what you posted should work great for the original question asked.