Search code examples
modxmodx-revolution

How to output a chunk or message if getPage is empty in MODX Revo 2.x


I have this construction:

[[!getPage? 
&element=`getResources` 
&limit=`10` 
&tpl=`vacancy_tpl` 
&parents=`[[*id]]` 
&includeContent=`1` 
&includeTVs=`1` 
&showHidden=`1` 
&pageFirstTpl=`<li class="control"><a[[+classes]][[+title]] href="[[+href]]">First</a></li>` 
&pageLastTpl=`<li class="control"><a[[+classes]][[+title]] href="[[+href]]">Last</a></li>
`]]

How can I output a message or chunk if there are no results returned by getPage call?


Solution

  • There is an easier way to do it, just use modx input/output filters -

    [[!getPage:empty=`<div>[[$your_chunk]] or your message</div>`? 
        &element=`getResources` 
        &limit=`10` 
        &tpl=`vacancy_tpl` 
        &parents=`[[*id]]` 
        &includeContent=`1` 
        &includeTVs=`1` 
        &showHidden=`1` 
        &pageFirstTpl=`<li class="control"><a[[+classes]][[+title]] href="[[+href]]">First</a></li>` 
        &pageLastTpl=`<li class="control"><a[[+classes]][[+title]] href="[[+href]]">Last</a></li>
    `]]