Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do exclude the current page from the display when using the Content by Label macro?

Sandy Johnson
Contributor
May 9, 2016

I use the Content by Label macro in many situations, but would like the page being viewed to not appear in the list generated. For example, I have 5 pages all related to Resource Management (my label). I want each of the 5 to display a link to the other 4 but not itself. How can I do that?

4 answers

3 votes
Deleted user March 7, 2017

We have the Cloud version of Confluence, so Stephen's solution won't work for us.

If your version of Confluence has CQL filters ("Add a filter" option), you can add a filter for the "With Title" field.

Enter the title of the page with a minus in front of it (e.g., "-My Page").  That's the only way I could figure out how to do it, except that it's a pain to have to explicitly enter the page name.  It would be nice if the macro could take an @self variable or something like it.  (Maybe it can, but I haven't found anything on it.)

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2017

I don't think it supports a reference to itself, but one option would be to use the CQL Search macro and simply use a CQL query like 

type=page AND space=spaceKey() AND id!=pageId() AND label=mylabel

and it would automatically generate a list of pages in the current space with that label excluding the current page.

Deleted user March 8, 2017

Thanks!  

I'll have to get approval to download and install the plugin, but this looks like the perfect solution for us.

Gabrielle

Deleted user July 24, 2017

We can't install Stephen's plugin, but the CQL query macro will take his filter.  Unfortunately, the CQL query macro (in Cloud version anyway) has a fixed report-style output format, with lines, a constant background color, etc., so it can't be used the way Content by Label is. It's not flexible enough. Why doesn't Atlassian listen to users, instead of always coming up with close, but not quite usable solutions.

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2017

Hi Gabrielle,

I did write the CQL query macro for Cloud, so I don't see why I couldn't implement a different display style as a new feature. Stay tuned!

(At least I'm assuming you're talking about the CQL Search add-on; it's not very clear from your comment as there is no built in CQL Search macro that I am aware of that allows you to reference the current page/space)

Deleted user July 25, 2017

No, I'm talking about a macro called CQL Query. We also have a Search Results macro that uses slightly different syntax:

ConfluenceMacros.pngNeither of these macros allows any user control of output. It's very frustrating.  It would be nice if the Content by Label macro, which does have output control, let us use a CQL query to refine the filter, instead of forcing us to use the crippled "user-friendly" interface.  There's nothing friendly about being stopped from doing very simple things. I found out the "With Title" filter allows only the CONTAINS operator. In other words, there isn't any way to exclude the current page, even by entering each title, because the filter won't accept any form of NOT. You can just filter labels that way.

Max Cascone
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2019

I'm late to this, and it's not a perfect answer, but i can confirm that @[deleted]'s hack of adding -The+Name+Of+The+Page to the Title field works. Obviously not a great solution for large Spaces.

SimonE
Contributor
January 19, 2021

The problem I've found with the With Title -{my page title} filter is that there doesn't seem to be any way to tell it to exclude only pages with that exact title.

The page I'm trying to add the filter to is called Reports.  However, there is another page which includes the word "Reports" in the title.  If I add a With Title filter of -Reports that will exclude both pages.  I've also tried -"Reports" (surrounding the page title in double quotes) and -'Reports' (surrounding the page title in single quotes), with no success.

1 vote
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2016

There's currently an open feature request for this feature:

https://jira.atlassian.com/browse/CONF-5245

But I did make a workaround until it can be implemented. I included a workaround in the ticket which I will duplicate here. If you include this in your Custom HTML (make sure you copy everything):

<script> $(function() { $('.content-by-label > li > div > a').filter(function() { return $(this).attr('href') === contextPath + '/pages/viewpage.action?pageId=' + AJS.params.pageId || $(this).attr('href') === contextPath + '/display/' + AJS.params.spaceKey + '/' + AJS.params.pageTitle.split(' ').join('+') }).parent().parent().hide().parent().next().filter('div').hide(); }); </script>

Then it will hide the current page from the results of the Content by Label macro. It's not perfect, but it should help.

Sandy Johnson
Contributor
May 10, 2016

Stephen

Thanks for the quick response. I have a couple of questions:

  1. being still relatively new to Confluence, how do I implement your script?
  2. in reading the related responses, it sounds like it doesn't work with the Documentation theme (which I'm using with version 5.8.13). Is that true?
  3. Finally, I went to the link you provided for the open link which looks like it was open in 2006, can this really be left open for 10 years? Also, it listed duplicate requests which were marked a completed which seems confusing.

Thanks again 

0 votes
Dmitry Ree
Contributor
July 25, 2019

This works for the server version:

If you have Source Editor then you can add “label=yourLabel and content != currentContent()”

Another solution is to highlight the title of the current page in bold using space style sheets similar to the Page tree macro.

Max Cascone
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2019

Not a solution for Cloud.

Dave Lines February 10, 2021

But works great on Server version. Thanks, @Dmitry Ree

0 votes
Andrey Khaneev _StiltSoft_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2017

Hi Sandy,

You can filter Content by Label macro table with Table Filter macro to hide the page.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events