Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Modify Content By Label Macro

smaida July 3, 2013

Hello,

Is it possible to modify a confluence macro such as "Content by Label"? I'd like to change a few aspects of it.

  1. Add content edit or publish date
  2. Modify the markup the macro produces

Is this possible? If not, can you provide any direction / resources for recreating the Content by Label macro with these changes?

Thanks!

-Shawn

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Tim
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 8, 2013

You can grab the source code here: https://bitbucket.org/atlassian/confluence-advanced-macros-plugin/src and build your own custom version of this macro by building a confluence plugin.

The files you need are:

  • LabelledContentMacro.java
  • labelledcontent.vm <- modify for your custom markup and add edit/publish date
  • atlassian-plugin.xml
$content.getCreationDate()
$content.getLastModificationDate()

smaida September 15, 2013

Thank you so much for your help (sorry it took me this long to get back). I haven't been able to get this working successfully, and need another nudge.

I've followed the tutorials, and copied / modified the mentioned files. The macro appears to install successfully; however, it never appears in the other macros list in the editor. Also, although the add-on shows as installed, I see the following in the terminal, so I suspect there is an issue.

How can I get more information on the error?

[INFO] [talledLocalContainer] 2013-09-16 01:14:14,816 INFO [UpmAsynchronousTaskManager:thread-1] [atlassian.plugin.manager.DefaultPluginManager] disableDependentPlugins Found dependent enabled plugins for uninstalled plugin 'com.itdp.confluence.macros': [].  Disabling...
[INFO] [talledLocalContainer] 2013-09-16 01:14:14,817 INFO [UpmAsynchronousTaskManager:thread-1] [atlassian.plugin.manager.DefaultPluginManager] updatePlugin Updating plugin 'com.itdp.confluence.macros' to 'com.itdp.confluence.macros'
[INFO] [talledLocalContainer] 2013-09-16 01:14:14,819 INFO [UpmAsynchronousTaskManager:thread-1] [atlassian.plugin.manager.DefaultPluginManager] notifyPluginDisabled Disabling com.itdp.confluence.macros
[INFO] [talledLocalContainer] 2013-09-16 01:14:14,829 INFO [UpmAsynchronousTaskManager:thread-1] [atlassian.confluence.plugin.ConfluencePluginManager] notifyUninstallPlugin Uninstalling com.itdp.confluence.macros

Thanks!

-Shawn

smaida September 15, 2013

Okay. I was able to get what I needed by starting with the entire advanced-macros source, and deleting what I didn't need. Right now, I'm trying to rename the contentbylabel macro, so that my macro is a new macro vs. edits to the existing. I can't seem to get the new macro to appear in the macro insert menu.

atlassian-plugin.xml

&lt;atlassian-plugin name='${project.name}' key='${atlassian.plugin.key}'&gt;
    &lt;plugin-info&gt;
        &lt;description&gt;${project.description}&lt;/description&gt;
        &lt;vendor name="ITDP" url="http://www.itdp.org/"/&gt;
        &lt;version&gt;${project.version}&lt;/version&gt;
        
    &lt;/plugin-info&gt;
    
    &lt;resource type="i18n" name="i18n" location="com/itdp/confluence/plugins/macros/advanced/i18n"/&gt;

    &lt;web-resource key="content-by-label-resources"&gt;
        &lt;resource name="content-by-label.css" type="download" location="com/itdp/confluence/plugins/macros/advanced/css/content-by-label.css"/&gt;
    &lt;/web-resource&gt;

    &lt;web-item key="itdpcontentbylabel" name="ITDP Content by Label" section="system.editor.featured.macros.default" weight="100"&gt;
        &lt;label key="ITDP Content by Label" /&gt;
        &lt;link linkId="itdpcontentbylabel" /&gt;
    &lt;/web-item&gt;

    &lt;macro name='itdpcontentbylabel' class='com.itdp.confluence.plugins.macros.advanced.LabelledContentMacro' key='itdpcontentbylabel'&gt;
        &lt;description&gt;List the pages labelled by a specified set of labels.&lt;/description&gt;
        &lt;resource type="velocity" name="help" location="com/itdp/confluence/plugins/macros/advanced/labelledcontent-help.vm"&gt;
            &lt;param name="help-section" value="confluence"/&gt;
        &lt;/resource&gt;
    &lt;/macro&gt;
&lt;/atlassian-plugin&gt;

smaida September 16, 2013

Alright. I'm really close now. Just need to get the macro's settings dialog to match that of the Content by Label macro.

0 votes
Matthew J. Horn
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 9, 2013

I also liked the Content By Label macro, but wanted to modify it without creating a plugin. I found this page (http://confluence.atlassian.com/display/DISC/Related+Content) which is a user-provided macro that wraps the content by label macro and provides some additional formatting and information.

My macro creates a list of 10 results, and does some other processing to remove the "Showing X of Y" text and strip out the leading and trailing <p> tags. You can see it in action on my company's doc pages (left gutter, under "Related Topics"): http://devcenter.verivo.com/display/doc/Creating+Custom+Modules

Here's my macro, which is a modification of the one I mentioned earlier:

## Related Content 2
##
## Created by: Matthew J. Horn
##
## This is a simplified version of http://confluence.atlassian.com/display/DISC/Related+Content
##
## @param NumLabels:title=Number of Labels|type=string|desc=Select the maximum number of labels to show

#set($wiki="")
#set($globalHelper=$action.getHelper())
#if($content) ## i. e. we render a normal page
  #set($renderer=$globalHelper.getWikiStyleRenderer())
  #set($context=$content.toPageContext())
  #set($labelList=$content.getGlobalLabels($action.getRemoteUser()))

  #if($labelList.size() &gt; 0)
    #set($labelUtil=$content.getLabelUtil())
    #set($labels=$labelUtil.convertToDelimitedString($labelList))
    #if($paramlabel)
      #set($labels=$labels + " " + $paramlabel)
    #end
    #if($paramlabels)
      #set($labels=$labels + " " + $paramlabels)
    #end

    ################################################
    ## For syntax of the contentbylabel macro, see https://confluence.atlassian.com/display/DOC/Content+by+Label+Macro
    ################################################
    #set($wiki="{contentbylabel:labels=$labels")
    #set($wiki=$wiki + "|showSpace=false")
    #set($wiki=$wiki + "|showLabels=false")
    #set($wiki=$wiki + "|max=$paramNumLabels")
    #set($wiki=$wiki + "}")

  #end
  #set($xhtml=$renderer.convertWikiToXHtml($context, $wiki))
#else ## we are e. g. in Global Template Preview
  #set($xhtml=$globalHelper.renderConfluenceMacro($wiki))
#end

## remove leading &lt;p&gt; and trailing &lt;/p&gt;
#if($xhtml.startsWith("&lt;p&gt;",0) &amp;&amp; $xhtml.endsWith("&lt;/p&gt;"))
  #set($len=$xhtml.length()-$generalUtil.convertToInteger(4))
  #set($xhtml=$xhtml.substring(3,$len))
#end

## Remove "Showing first XX of YY results" if it appears, after trimming
## FYI: $xhtml is a Java String
#if($xhtml.trim().endsWith("results"))

  ## Set $len to the length of the $xhtml block, minus 30 characters (after trimming)
  #set($len=$xhtml.trim().length() - $generalUtil.convertToInteger(30))

  ## Set $xhtml to be a substring from the first character (0) to the $len-th character
  #set($xhtml=$xhtml.trim().substring(0,$len))
#end

## Print out the results:
${xhtml}
TAGS
AUG Leaders

Atlassian Community Events