Is there a way to conditionally supress a macro's results? {Content by Label} macro returns "No content found for label(s) x."

I was trying to use the {content by label} to build tables of contents.

Basically I want to maintain a "master list" of all customers with each customer having their own page (and children). I want to then build smaller lists of customers based on what level of service they subscribe to. So I could have Company X that is labeled "customer" "LEVEL2" and "x". I want to list this customer in the master customer list and I also want to list this customer under our "Level 2 Customer List". I want the lists to dynamically be built based on current pages that match the criteria. That way we can edit the customer data, add or remove labels based on changes in their service level, and the contents lists would automagically be updated with the new page labeling.

The problem with this plan is that if I have no matching results to display (no Level 2 customers that begin with the letter "Q" for instance), I get an unattractive "No content found for label(s) q" result. I would like to conditionally suppress any blank results but I haven't found a way to accomplish that.

Any ideas? Is there a better way to build dynamic indexes with conditional blank space supression within confluence?

1 answer

1 accepted

Hey Ken,

Please correct me if I'm wrong, but you want to suppress if the message is "No labels found" and show if there is labels. Right? This would confuse some users, if they are using it, BUT, if you want to use it for you, and know that it would be shown as you want, then I've written a custom User Macro just for you :)

  1. Name
  2. Title
  3. Rendered
  4. And the Code
    ## @noparams
    ## This sets the variable to see if it contains a word
    #set ($bodyContent = $body)
    ## Then checks if it has no labels, and it does a custom message, or could be empty :)
    #if ($bodyContent.contains("No content found for label(s)"))
    There is no Cookie for you

Hope this is what you wished for, if not let me know and I can try to tweak it more!


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

1,038 views 51 8
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you