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

    Super simple question; I’m looking for a code snippet which will just print the name of the parent folder of the section/page I’m in. So for example, if I’m in the section "How We Help," I just need that text to print on the screen for that page and any of the pages/documents in that folder. Thank you!

    - Jess
      • 20508
      • 157 Posts
      Thank you. I’ve got the snippet installed and am using the snippet call you supplied - but for some reason the snippet call instead of the actual page title is printing out on the page. You can see it here: http://a2s38.a2hosting.com/~cfknyc/newcfk.com/about-change-for-kids
        • 20508
        • 157 Posts
        Just realized the exclamation marks were missing, the call should be: [[!getField? &docid=`[*parent*]` &field=`pagetitle`!]]
        I included them, but now nothing is showing up. tongue
          • 29076
          • 615 Posts
          You must use either [[ .. ]] (cached) or [! .. !] (non-cached), not [[! .. !]]. smiley
            I think, thererfor I am! But what I am, and why...?
            • 20508
            • 157 Posts
            Thanks Sylvaticus. I tried both of these:

            [[getField? &docid=`[*parent*]` &field=`pagetitle`]]
            [!getField? &docid=`[*parent*]` &field=`pagetitle`!]

            They still both print out the actual snippet text, not the pagetitle of the parent docid. Even when I used this: [!getField? &docid=`[*parent*]` &field=`pagetitle`!], it printed this: [[getField? &docid=`[*parent*]` &field=`pagetitle`]].

            Ahhh! smiley

              • 29076
              • 615 Posts
              You can also try GetParent, http://modxcms.com/extras.html?view=package/view&package=174, but I don’t know if it works with .0.9.6.3. smiley
                I think, thererfor I am! But what I am, and why...?
                • 20508
                • 157 Posts
                Thanks again.
                I’m getting a parsing error - maybe it’s an issue regarding the version of MODx as you said:

                « PHP Parse Error »

                PHP error debug
                Error: include_once(assets/libs/docapi/docapi.class.inc.php) [function.include-once]: failed to open stream: No such file or directory

                No luck for me today here! Think I’m going to give it a breather.
                  • 16183
                  • 1,390 Posts
                  Jess,

                  Can you confirm that you correctly installed the getField snippet? E.g., did you include the <?php.... ?> tags?

                  Also .......

                  You may get frustrated if you try to enter your Snippet call into the content field with the TinyMCE editor running... it will want to replace the ampersand with the html equivalent, and your Snippet input parameters will be malformed. You can turn off the TinyMCE editor in your user’s configuration, or try entering the Snippet call into another field, e.g. the Summary (introtext), just make sure that template variable appears in your template.

                  /k
                    • 20508
                    • 157 Posts
                    Hi Kongondo,

                    Thanks for your reply. I didn’t see any explicit instructions for this snippet, so I took the contents of the text file download (below) and called the snippet "GetParent" The snippet call is within a chunk and is: [!GetParent? &field=`pagetitle`!]. Is my snippet call incorrect? (I’ve also got the editor off during editing).

                    - Jess



                    /**
                    * GetParent
                    * ---------
                    * Get the parent object from the current document parent. If there is
                    * no parent, it will return empty. This snippet will not fetched the
                    * parent object multiple times when it’s called several times in the
                    * document.
                    *
                    * Author: Wendy Novianto
                    * Version : 0.2
                    * License: GPL
                    * Tested On: MODx 0.9.2.1
                    * Required: docAPI library
                    *
                    * History:
                    * - 0.1 - First initial public released of the snippet
                    * - 0.2 - Added support for fetching parents document fields in multiple level
                    *
                    * Parameters:
                    * - $field - Name of the document/template variable to be outputed
                    * - $formatted - Set it to true to output the TV in formatted output, default false
                    * - $level - Start from 0 to infinity
                    */

                    if(!isset($field)) return ’’;
                    else $field = trim($field);

                    if(!isset($level) || !is_numeric($level)) $level = 0;
                    else $level = (int) $level;

                    if(isset($formatted) && $formatted) $formatted = true;
                    else $formatted = false;

                    include_once(’assets/libs/docapi/docapi.class.inc.php’);

                    if(isset($modx->parentDocObject[$level]) && is_array($modx->parentDocObject[$level])) {
                    if(isset($modx->parentDocObject[$level][$field])) return ($formatted) ? $modx->parentDocObject[$level][$field.’_output’] : $modx->parentDocObject[$level][$field];
                    }
                    else {
                    $objectDocAPI = new docAPI();
                    for($i = 0; $i <= $level; $i++) {
                    if(!isset($modx->parentDocObject[$i]) || !is_array($modx->parentDocObject[$i])) {
                    if($i == 0) $parent = $modx->documentObject[’parent’];
                    else $parent = $modx->parentDocObject[$i-1][’parent’];
                    if($parent > 0) {
                    $docObject = $objectDocAPI->staticGetDocuments($parent);
                    if(is_array($docObject) && count($docObject) == 1) {
                    $modx->parentDocObject[$i] = $docObject[0];
                    }
                    }
                    else $i = $level + 1;
                    }
                    }
                    if(isset($modx->parentDocObject[$level][$field])) return ($formatted) ? $modx->parentDocObject[$level][$field.’_output’] : $modx->parentDocObject[$level][$field];
                    }
                    return ’’;
                      • 16183
                      • 1,390 Posts
                      GetField: if you installed it following the info in the GetField.txt - note that the spelling and case - snippets, chunks, etc names are case sensitive. So, if you named the snippet GetField then the call should be....

                      [[GetField? &docid=`[*parent*]` &field=`pagetitle`]]


                      But you may need to call it uncached on cached pages, like so

                      [!GetField? &docid=`[*parent*]` &field=`pagetitle`!]


                      Tested it and it works fine - even when using TinyMCE wink

                      cheers/k