【问题标题】:If getResources parent is not empty display chunk如果 getResources parent 不为空,则显示块
【发布时间】:2013-08-06 16:02:30
【问题描述】:

我是 modx 世界的菜鸟。我有一个包含子页面的页面,我使用 getResources 在父页面的选项卡中显示这些内容。

如果父页面有子页面,我想做的只是显示该块?

像这样,但这显然是不对的,因为它不起作用。

[[!getResources &parent:notempty=`[[$chunk]]`]]  

【问题讨论】:

    标签: filter modx-revolution modx-resources modx-chunks


    【解决方案1】:

    试一试,为此创建一个新的 sn-p;

    <?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;
    

    【讨论】:

      【解决方案2】:

      它是 &parents ,带有“s”。

      无论如何, 如果要对 sn-p 使用输出过滤器,请将其添加到问号之前:

      [[!getResources:isempty=`No content is available`? &parents =`[[*id]]`]]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-28
        • 1970-01-01
        • 1970-01-01
        • 2016-03-08
        相关资源
        最近更新 更多