This server will be upgraded at 3pm Sydney time on December 3rd (December 2nd, 8pm PST) and will be down for up to 30 minutes.
This documentation relates to the latest version of Confluence.
If you are using an earlier version, please go to the documentation home page and select the relevant version.

Content by Label Macro

All Versions
Click for all versions
Confluence 2.10 Documentation

Index

The Contentbylabel macro lists content which has been tagged with specific labels.

On this page:

Usage

What you need to type What you will get
{contentbylabel:documentation, my:stuff|maxResults=5}
Confluence Internals (Confluence Docs 2.10) Labels: confluence, internal, documentation
Related Labels Macro (Confluence Docs 2.10) Labels: documentation, confluence-label-filter
Character encodings in Confluence (Confluence Docs 2.10) Labels: character, encoding, unicode, utf8, confluence, database, http, internal, documentation
Working with Macros (Confluence Docs 2.10) Labels: confluence, macro, list, all, summary, index, documentation
Confluence Documentation Home (Confluence Docs 2.10) Labels: documentation, installation, example, admin
Showing first 5 of 6 results


By default, Confluence lists all the labels for each result displayed. In the above example, we have limited the list to 5 results. See the optional parameters below for more information.

Recommended Default Usage

To display all pages with the label needs-fixing, use:

{contentbylabel:needs-fixing|showLabels=false|maxResults=99|showSpace=false|key=@self}

Optional Parameters

No  Parameter Default Description
 1 key all Specify a space key to show the results for a particular space.
Keywords: @all shows results from all spaces; @self shows results from only the current space.
 2 type false Filter by content type
 3 showLabels true Show or hide labels for results
 4 showSpace true Show or hide spaces for results
 5 excerpt false Show or hide excerpts for results
 6 maxResults 5 Specify maximum results to display
 7 sort=creation
sort=title
sort=modified
recent The 'sort' attribute is an optional attribute that allows you to configure how the children are sorted. You can also use the 'reverse' parameter (see below) to optionally reverse the sorting.
 8 reverse=true false If you are using the 'sort' parameter (see above), you can also use the 'reverse' parameter change the sort order.
 9 operator OR The operator to apply to the supplied lists of labels. By default, a page with any of the labels will be listed. By using operator=AND, only pages with all of the supplied labels will be listed.

Examples

1. Filter by space

{contentbylabel:dogs,cats|key=PETS}

2. Show only results in current space

{contentbylabel:dogs,cats|key=@self}

3. Show results from all spaces

{contentbylabel:dogs,cats|key=@all}

4. Filter by content type: pages or blog posts

{contentbylabel:dogs,cats|type=page,blogpost}

5. Hide labels for results

{contentbylabel:dogs,cats|showLabels=false}

6. Hide spaces for results

{contentbylabel:dogs,cats|showSpace=false}

7. Display excerpts for results

{contentbylabel:dogs,cats|excerpt=true}

8. Specify the maximum number of results to display

{contentbylabel:dogs,cats|maxResults=99}

9. Sort by creation date, modification date or title

{contentbylabel:dogs,cats|sort=title}

10. Change the sort order

{contentbylabel:dogs,cats|sort=title|reverse=true}
RELATED TOPICS

Related Labels Macro
Navmap Macro
Recently Used Labels Macro
Working with Labels Overview
Working with Macros

Take me back to Confluence User Guide

Labels

label label Delete
filterbylabel filterbylabel Delete
contentbylabel contentbylabel Delete
related related Delete
similar similar Delete
topic topic Delete
content content Delete
confluence-label-filter confluence-label-filter Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jan 11, 2008

    Anonymous says:

    I would like the output to be just the page names as links, separated by spaces....

    I would like the output to be just the page names as links, separated by spaces.  No icon, no "new line", no Space or Labels.  In this way I can, for example, create a table and fill a cell with links for a label-defined collection of pages.  A very dense way to build a reference page to items for sets of topics. Please!?

    Is this doable as a user macro?  Would the current source be a big help?

    Thanks! - Tom Evans 

    1. Jan 14, 2008

      Anonymous says:

      Here is a great example of how this capability would be used:   enter...

      Here is a great example of how this capability would be used:

        enterprisearchitecture.nih.gov
       

      The front page of this Enterprise Architecture site gives instant access to a large set of standards, organized by category.  A perfect use of  labels and content-by-label.  If these links were listed as one-per-line this Front Page would be three pages long, at least.

      1. Jan 14, 2008

        James Mortimer says:

        you could use the Reporting Plugin (if it's installed) you could use this hor...
        • you could use the Reporting Plugin (if it's installed)
        • you could use this horrible user macro hack below. Uses metadata-report from the Metadata Plugin. By using metadata-report, you can use basic label logic, i.e. 'software+documentation' requires both labels. you could alter it to wrap the built in contentbylabel aswell.
        • the trimp and render velocity template definitions may not be needed if they are declared elsewhere
        ## Macro: contentbylabel2
        ## Macro does not have a body
        ## Macro returns HTML
        ##
        #macro(trimp $xhtml)
        ## remove leading <p> and trailing </p>
        #if($xhtml.startsWith("<p>",0) && $xhtml.endsWith("</p>"))
        #set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
        #set($xhtml=$xhtml.substring(3,$len))
        #end
        $xhtml
        #end
        ##
        #macro(render $wiki)
        ## render $wiki in wiki renderer
        #set($globalHelper=$action.getGlobalHelper())
        #if($content) ## i. e. we render a normal page
          #set($renderer=$globalHelper.getWikiStyleRenderer())
          #set($context=$content.toPageContext())
          #set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
        #else ## we are e. g. in Global Template Preview
          #set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
        #end
        #trimp($xhtml)
        #end
        ##
        ## Get parameters
        ##
        #set($key="")
        #if($paramkey)#set($key=$paramkey)#end
        #if($key.length()>0)#set($key="|key=$key")#end
        ##
        #set($sort="")
        #if($paramsort)#set($sort=$paramsort)#end
        #if($sort.length()>0)#set($sort="|sort=$sort")#end
        ##
        #set($delimiter=" ")
        #if($paramdelimiter)#set($delimiter=$paramdelimiter)#end
        ##
        #set($labels="")
        #if($param0)#set($labels=$param0)#end
        #if($paramlabels)#set($labels=$paramlabels)#end
        #if($labels.length()>0)#set($labels="|labels=$labels")#end
        ##
        ## retrieve pages with those labels (uses metadata-report for now)
        ##
        #set($wiki="{metadata-report:Title${labels}${key}${sort}}")
        #set($html="#render($wiki)")
        ##
        ## pull out just urls, skipping first array element
        ##
        #set($hrefs=$html.split('<a href='))
        #foreach($href in $hrefs)
        #if($velocityCount>1)
        #set($index=$href.indexOf("</a>")+$generalUtil.convertToInteger(4))
        #set($href="<a href=$href.substring(0,$index)")
        #if($velocityCount>2)
        $delimiter
        #end
        $href 
        #end
        #end
        
        1. Jan 14, 2008

          Anonymous says:

          Wow. Thanks! This client site needs to get through an upgrade first (2.0.2 ...

          Wow. Thanks!

          This client site needs to get through an upgrade first (2.0.2 -> 2.7), so I won't be reporting success for (at least) a few weeks, but its great to see a solution, and community support in action.  - Tom

  2. Apr 30, 2008

    Jes Deamer says:

    Is there anyway to do some kind of exclusion criterion? say contentbylabel: '...

    Is there anyway to do some kind of exclusion criterion? say

    contentbylabel: 'dogs' is not an existing label

    The practical application would be having a set of documents on varying yet very similar topics, wanting to display all except a particular subset that is flagged for review. Since I'd need to use more than one set of labels, I'm hard pressed to say ONLY dogs and reviewed, as I need cats as well, so setting the AND operator doesn't catch all the content, and OR sets the net too wide.

    1. Apr 30, 2008

      David Peterson [CustomWare] says:

      You can do it with the Reporting Plugin. The 'labels' parameters on several macr...

      You can do it with the Reporting Plugin. The 'labels' parameters on several macros there will let you specify "+" or "-" for "required" and "excluded", respectively. So, for example, you could do this:

      {report-list}
      {content-reporter:space=+@global, -EXCLUDED|labels=+dogs, +cats, -needs_review|type=page}
        {text-sort:content:title}
      {content-reporter}
      
      {report-body}{report-info:content:title|link=true}{report-body}
      
      {report-list}
      

      Which would basically give you all pages in all global (non-personal) spaces except the one called 'EXCLUDED' which have the 'dogs' and 'cats' label, but do not have 'needs_review'.

  3. Sep 05

    Anonymous says:

    I see where the type "page" and blog-post" work, but I dont; see a full list fo ...

    I see where the type "page" and blog-post" work, but I dont; see a full list fo other "types"

     in the search macro documentation I see a list of types- but they don't seem to be consistent -- I see "userinfo",  but I can't get any of these to work using this contentby label macro:

    userinfo, user-indo, user, users, profile, profiles, user-profile....

     in the search macro I see "blogpost" type but in this macro it is blog-post...  Is there some consistency that will be achieved here at some point? what types does this macro support right now? if not all- why?


    1. Sep 29

      Ming Giet Chong says:

      Hi, For Content by label macro, it's different with the space macro whereby it ...

      Hi,

      For Content by label macro, it's different with the space macro whereby it lists content with tagged labels. That means, it could be either page or blogs post. Having said that, labels work in pages and blogs post. In this macro, the "blogpost" type is used. For example:

      {contentbylabel:dogs|type=blogpost}
      

      Hope this helps. Thanks.

      Regards,
      MG

  4. Sep 15

    Anonymous says:

    Can you pull attachments in with this macro?  Say I am pulling all pages wi...

    Can you pull attachments in with this macro?  Say I am pulling all pages with the labels Forms and Policies.  Though all of our forms and policies are attachments.  Could it look like this?

     IT Forms and Policies:

    - Internet usage policy (Actual link to the word document policy)

    - Email Policy (Actual link to the word document policy)

    1. Sep 16

      Azwandi Mohd Aris says:

      Hi there, I am afraid that this is not possible since the supported content typ...

      Hi there,

      I am afraid that this is not possible since the supported content types are page and blogpost only. The attachment macro might be the closest to your requirement, however there is no labelling capabilities.

      However, there is an ongoing feature request at CONF-3963 to allow attachments to be labelled, and hence can be further utilised by the attachment macro to filter out the attachments according to labels: CONF-9639. Hope that helps.

      Cheers,
      Azwandi

Add Comment