Hi,
I am trying to build a confluence plugin, and one of my macro's requires the user to upload an image.
I've tried using your
<parameter name="secondImg" type="attachment" required="true"/>
xml under the "parameters" tag in the "atlassian-plugin.xml" file.
When I try to use it I get an empty select box with no options to search\choose attachments.
I know this was an issue before but according to my understanding it was solved.
I am using Confluence V4.3.1
Thanks!
Community moderators have prevented the ability to post new answers.
OK, there's an easy way to do this and a hard way to do this. Unfortunately, just setting the parameter type to "attachment" doesn't do anything - you still need to add some JavaScript into your plugin to 'activate' it.
The easy way is pretty straight-forward, but doesn't provide a lot of configuration or flexibility. This is a wrapper around the more complex configuration option:
1) Edit your atlassian-plugin.xml and define your macro's parameter as follows:
<parameters> <parameter name="page" type="confluence-content"/> <parameter name="name" type="attachment" required="true"/> </parameters>
Note:
- You must have a "page" parameter.
- The attachment parameter must be called "name".
2) Add a JavaScript file to your plugin. The contents of this file should be as follows:
(function($) { var macroName = "my-macro"; var attachmentFileTypes = ["txt", "rtf", "doc"]; AJS.MacroBrowser.activateSmartFieldsAttachmentsOnPage(macroName, attachmentFileTypes); })(AJS.$);
Note:
- macroName is the name of your macro.
- attachmentFileTypes is the file extension of the attachments that you want to appear in the attachments parameter.
3) Add this JavaScript file to your plugin as a web-resource. The web-resource requires a context of "macro-browser" in order to be picked up and served in the correct location. Your web-resource declaration should look like this:
<web-resource name="macro-resources" key="macro-resources"> <resource type="download" name="examplemacro.js" location="scripts/examplemacro.js"/> <dependency>confluence.editor.actions:editor-macro-browser</dependency> <context>macro-browser</context> </web-resource>
Note:
- example.js is the name of the JavaScript file you created in 2).
This is the easiest way you can get it working, but as you can see, you are restricted in the name of the attachment parameter (it must be 'name') and you must also have a 'page' parameter on the macro.
If this isn't suitable for you, you'll need to interact with the Macro Browser's JavaScript API directly to set up the parameter the way you want it. It's a bit too complex to try and describe here, but if you have access to the Confluence source code (highly recommended for any serious Confluence plugin development) you should look for the macro-browser-smartfields.js file in the Confluence core webapp project.
Hope this helps!
Is this still valid in 2015? I've the same problem, but need two fields for selecting attachments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm facing the same issue like George in Confluence 6.12.3 using SDK 6.2.6
All my old plugins works perfectly fine able to list the attachments in the dropdown but when i tried creating a new plugin, with all the above confluence-core-macro-fields.js to filter out and this in the atlassian-plugin.xml, it doesn't work now:
<web-resource key="macro-browser-smart-fields" name="Macro Browser Smart Fields">
<resource type="download" name="confluence-core-fields.js" location="/js/confluence-core-macro-fields.js" />
<dependency>confluence.editor.actions:editor-macro-browser</dependency>
<context>macro-browser</context>
</web-resource>
<parameter name="name" type="attachment" required="false">
<option key="showKeyInPlaceholder" value="false" />
<option key="showValueInPlaceholder" value="true" />
</parameter>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This answer (the "easy" solution) does not seem to be valid anymore.
Using SDK 6.2.15 and Confluence 5.10.2.
As soon as I include the suggested Javascript, the page Editor won't load anymore.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot! This has been very helpful!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've updated to Confluence V4.3.2
Issue still continues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.