Hi all. My first snippet that I feel is actually worth sharing. It seems like every site I do in MODx I want child docs to inherit TV values from their parents, so I made this snippet.
How to use: Set [!InheritTV!] as the default TV value; whenever you set a document’s TV value, all the children of that document will "inherit" that TV value.
It could be better: It only works for the parent doc and will not go up the tree any higher. So, if a document’s
grandparent has a TV assigned, but the parent does not, it doesn’t work. (It actually returns [!InheritTV!].) If anybody can offer some advice to get that working it’d be swell.
// CONFIGURABLE OPTIONS
// Set the $tvIdNage to equal the TV you are inheriting.
// Example: The TV is called HeaderImg, so you'd find
// the id of that TV, or call it by name
// [!InheritTV?tvIdName=`HeaderImg`!]
$tvIdName = (!isset($tvIdName)) ? '1' : "$tvIdName";
// END CONFIG
$id = $modx->documentIdentifier;
$pid = $modx->getParent($id,1,"id");
$pid = $pid['id'];
$ptv = $modx->getTemplateVarOutput($tvIdName,$pid,1);
$output = '';
foreach($ptv as $feld => $value) {$output = $value;}
return $output;
The $id and $pid are from Susan’s UltimateParent. Also,
I’m fully aware that my PHP sucks, so feel free to offer suggestions.