我是modx世界中的一个小人物。我有一个包含子页面的页面,我使用getResources在父页面的选项卡中显示这些页面的内容。
我想做的是,如果父级有子页面,只显示该区块?
所以像这样的事情,但这显然是不对的,因为它不起作用。
[[!getResources &parent:notempty=`[[$chunk]]`]]
尝试一下,为它创建一个新的片段;
<?php
// get the current resource id
$id = $modx->resource->get('id');
// get the resource object
$resource = $modx->getObject('modResource', $docId);
// make sure we have a resource
if($resource){
// see if the resource has children
$hasChildren = $resource->hasChildren();
if($hasChildren){ // pretty sure hasChildren returns 1 or 0
// optionally, retrieve the chunk & populate it.
// replace your-chunk-name and the placeholders with your values.
$output = $modx->getChunk('your-chunk-name',array(
'placeholder-1-name' => 'value',
'placeholder-2-name' => 'value',
'placeholder-3-name' => 'value',
'placeholder-4-name' => 'value',
));
return $output;
}
}
return true;
它是&父母,带"s"。
不管怎样,如果你想对代码段使用输出过滤器,你可以在问号之前添加它:
[[!getResources:isempty=`No content is available`? &parents =`[[*id]]`]]