Hello,
Is it possible to modify a confluence macro such as "Content by Label"? I'd like to change a few aspects of it.
Is this possible? If not, can you provide any direction / resources for recreating the Content by Label macro with these changes?
Thanks!
-Shawn
Community moderators have prevented the ability to post new answers.
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:
$content.getCreationDate() $content.getLastModificationDate()
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
<atlassian-plugin name='${project.name}' key='${atlassian.plugin.key}'> <plugin-info> <description>${project.description}</description> <vendor name="ITDP" url="http://www.itdp.org/"/> <version>${project.version}</version> </plugin-info> <resource type="i18n" name="i18n" location="com/itdp/confluence/plugins/macros/advanced/i18n"/> <web-resource key="content-by-label-resources"> <resource name="content-by-label.css" type="download" location="com/itdp/confluence/plugins/macros/advanced/css/content-by-label.css"/> </web-resource> <web-item key="itdpcontentbylabel" name="ITDP Content by Label" section="system.editor.featured.macros.default" weight="100"> <label key="ITDP Content by Label" /> <link linkId="itdpcontentbylabel" /> </web-item> <macro name='itdpcontentbylabel' class='com.itdp.confluence.plugins.macros.advanced.LabelledContentMacro' key='itdpcontentbylabel'> <description>List the pages labelled by a specified set of labels.</description> <resource type="velocity" name="help" location="com/itdp/confluence/plugins/macros/advanced/labelledcontent-help.vm"> <param name="help-section" value="confluence"/> </resource> </macro> </atlassian-plugin>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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() > 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 <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 ## 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}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.