Sorry, it’s kinda off-topic to the current conversation.
Anyway, I found a bug in @INHERIT binding and getTemplateVarsOutput API. As far as I know, it only affect Newslisting snippet.
Here is the problem.
I create a TV called block_inherit. I set the default value to @INHERIT.
Now I create this kind of folder format.
parent
|- subfolder1
|- document1
|- document2
|- document3
If I called newslisting snippet in subfolder1 to display its own subdocuments, then it will works just fine. Now if I called newslisting snippet in parent document and pass startID parameter to display subfolder1 children, it will display a different TV output, because the @INHERIT is being calculated from parent folder id, instead of subfolder1 id.
The problem is being caused by the ProcessTVCommand function. When newslisting snippet is calling getTemplateVarOutput API, it will basically called the ProcessTVCommand without passing the requested document id. Inside the ProcessTVCommand, the @INHERIT binding always assume that the incoming request will always be from the current document id, while it’s not correct when ProcessTVCommand is being used by the getTemplateVarOutput API outside the current document id.
There are several ways to fix this. What I’m gonne present in here will be using a global variables, which in my opinion, it’s not a clean solution. Another way to do it, is to change each getTVDisplayFormat and ProcessTVCommand function an extra parameter called $docid.
Here is the fix with the first solution.
In document document.parser.class.inc.php, look for getTemplateVarOutput function and change it with this.
# returns an associative array containing TV rendered output values. $idnames - can be an id or name that belongs the template that the current document is using
function getTemplateVarOutput($idnames=array(), $docid="", $published=1) {
if(count($idnames)==0) {
return false;
}
else {
$output = array();
$result = $this->getTemplateVars(($idnames=='*' || is_array($idnames)) ? $idnames:array($idnames),"*",$docid,$published,"",""); // remove sort for speed
if ($result==false) return false;
else {
$baspath = $this->config["base_path"]."manager/includes";
include_once $baspath."/tmplvars.format.inc.php";
include_once $baspath."/tmplvars.commands.inc.php";
for($i=0;$i<count($result);$i++) {
$row = $result[$i];
// to-do needs fixing when getting tvs from other pages
$replace_richtext = "";
$richtexteditor = "";
$w = "100%";
$h = "300";
// BEGIN - FIXED @INHERIT binding to inherit from the given doc id, instead of current doc id
// Modified by Wendy Novianto
$GLOBALS['fixed_inherit_docid'] = $docid;
$output[$row['name']] = getTVDisplayFormat($row['name'],$row['value'],$row['display'],$row['display_params'],$row['type']);
unset($GLOBALS['fixed_inherit_docid']);
// ENDED - FIXED @INHERIT
}
return $output;
}
}
}
In document tmplvars.commands.inc.php, look for case "@INHERIT".
case "@INHERIT":
$output = $param; // Default to param value if no content from parents
// BEGIN - FIXED @INHERIT binding to inherit from the given doc id, instead of current doc id
// Modified by Wendy Novianto
if(!isset($GLOBALS['fixed_inherit_docid']) || !is_numeric($GLOBALS['fixed_inherit_docid']))
$GLOBALS['fixed_inherit_docid'] = $modx->documentIdentifier;
$doc = $modx->getDocument($GLOBALS['fixed_inherit_docid'],'id,parent');
// ENDED - FIXED @INHERIT
while($doc['parent'] != 0) {
$parent_id = $doc['parent'];
if($doc = $modx->getDocument($parent_id, 'id,parent')) {
$tv = $modx->getTemplateVar($name, '*', $doc['id']);
if($tv['value'] && substr($tv['value'],0,1) != '@') {
$output = $tv['value'];
break 2;
}
} else {
// Get unpublished document
$doc = $modx->getDocument($parent_id, 'id,parent',0);
}
}
break;
That’s all.
Hope it will be fixed in 0.9.2 release.
Take care...
ADDED: Bug tracker:
http://modxcms.com/bugs/task/337