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
You must use either [[ .. ]] (cached) or [! .. !] (non-cached), not [[! .. !]].
I think, thererfor I am! But what I am, and why...?
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.
I think, thererfor I am! But what I am, and why...?
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.
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 ’’;