I have a simple TV to build a multi-select Listbox of all children/grandchildren for a given UltimateParent.
[table]
[tr][td]TV Properties[/td][td](none)[/td][/tr]
[tr][td]TV Input[/td][td]Listbox (multi-select)[/td][/tr]
[tr][td]TV Input Option values[/td][td]@EVAL return $modx->runSnippet(’AllRelatedPages.TV’);[/td][/tr]
[tr][td]TV Input Default value[/td][td][/td][/tr]
[tr][td]TV Output Type[/td][td]Delimiter[/td][/tr]
[tr][td]TV Output Delimiter[/td][td],[/td][/tr]
[/table]
Here is the
AllRelatedPages.TV snippet:
<?php
$parent = $modx->getOption('parent',$scriptProperties,$modx->runSnippet('UltimateParent'));
$relatives = $modx->getChildIds($parent,5);
$resources = array();
foreach($relatives as $relative) {
$Relativeobject = $modx->getObject('modResource',$relative['id']);
if (is_object($Relativeobject)) {
$resources[] = $Relativeobject->get('pagetitle').'=='.$Relativeobject->get('id');
}
}
$output = implode("||",$resources);
return $output;
When I run the snippet directly it returns the correct child/grandchild pages in the correct format:
pagetitle1==1||pagetitle2==2||pagetitle3==3
However, when I access the TV in a resource the Listbox is empty.
I have an identical TV that runs a different snippet to get immediate children only for a given UltimateParent.
Here is the RelatedPages.TV snippet:
<?php
$parent = $modx->getOption('parent',$scriptProperties,$modx->runSnippet('UltimateParent'));
$Parentobject = $modx->getObject('modResource',$parent);
if (is_object($Parentobject)) {
$resources = array();
$resources[] = $Parentobject->get('pagetitle') . '==' . $Parentobject->get('id');
$Childobjects = $Parentobject->getMany('Children');
foreach($Childobjects as $Childobject) {
if (is_object($Childobject)) {
$resources[] = $Childobject->get('pagetitle') . '==' . $Childobject->get('id');
}
}
}
$output = implode("||",$resources);
return $output;
The RelatedPages.TV snippet returns its output in the same format:
pagetitle1==1||pagetitle2==2||pagetitle3==3
and the Listbox is populated correctly.
I dont understand why the TV that runs the
AllRelatedPages.TV snippet renders an empty Listbox.
Any help will be appreciated.
Thanks