We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4395
    • 13 Posts
    I’ve got news section on my page - something like:

    <h1>News</h1>
    [[$news-section]]
    


    Inside the news-section snippet there is a getResource call.
    What I want to do is to not show this whole section if getResource returns no news at all.
    Is there any easy and DRY way to do it?

    PS. I’ve tried output filters like :ifempty etc, but unfortunatelly getResource in chunk is not parsed, so ifempty is always false.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I don’t know about DRY, but couldn’t you have the getResource function (not in a chunk) save its output to a placeholder, then use the conditional on the placeholder?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 36416
        • 589 Posts
        Quote from: bx2 at Sep 06, 2010, 08:55 PM

        <h1>News</h1>
        [[$news-section]]
        


        Inside the news-section snippet there is a getResource call.
        What I want to do is to not show this whole section if getResource returns no news at all.
        Is there any easy and DRY way to do it?

        You could try wrapping the title inside first template for GetResources (tpl_{n} syntax):
        http://rtfm.modx.com/display/ADDON/getResources


        P.S: don’t have Revo public release installed anywhere handy... wink
          • 4395
          • 13 Posts
          Quote from: sottwell at Sep 07, 2010, 12:10 AM

          I don’t know about DRY, but couldn’t you have the getResource function (not in a chunk) save its output to a placeholder, then use the conditional on the placeholder?

          Heh - I didn’t thought about that:) I think it will be the best solution and also the easiest one to implement - I will try it and get back to you smiley
          Thanks
            • 4395
            • 13 Posts
            Quote from: sottwell at Sep 07, 2010, 12:10 AM

            I don’t know about DRY, but couldn’t you have the getResource function (not in a chunk) save its output to a placeholder, then use the conditional on the placeholder?

            Ok - I’ve got it working - example code below for others:

            [[!getResources? 
              &parents=`41` 
              &hideContainers=`1` 
              &tpl=`publication-list` 
              &toPlaceholder=`publication-list`
              &limit=`5` 
              &sortby=`publishedon` 
              &includeTVs=`1` 
              &processTVs=`1` 
              &tvFilters=`specializations==%[[*id]]%`
            ]]
            
            [[!+publication-list:notempty=`
            <div id="pubs">
            <h1 class="decorated"><span>Publikacje</span></h1>
            <ul class="pub-list">
            [[+publication-list]]
            </ul>
            (...)