It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Adding a 'configure' page to my Add-On in confluence.

I have written a Confluence Macro that needs the admin to setup a default value that will be system wide. My macro will then need to pull this default value and use it. At the moment I have simply hard coded it in my Macro. Obviously this is not desirable as I would have to modify the Macro for every system that uses it.

I believe that this should be done using the 'configure' button from the Add-Ons page for my Macro.

I have been looking for some sample code of a Macro that has this in it but can't find any and am at a loss as to how to find out how to do this.

Can anyone give me some tips/hints/ideas where I might find out how to do this?

1 answer

Hi Stephen

Take a look at the Markdown for Confluence add-on, particularly the ConfigurationServlet and the soy template md-configure.soy:

ConfigurationServlet:
https://bitbucket.org/dvdsmpsn/markdown-for-confluence/src/6f97807fc7abc919cb325dc3e1a2d0e8b12c884c/src/main/java/me/davidsimpson/confluence/addon/markdown/servlet/ConfigurationServlet.java?at=master

md-configure.soy:
https://bitbucket.org/dvdsmpsn/markdown-for-confluence/src/6f97807fc7abc919cb325dc3e1a2d0e8b12c884c/src/main/resources/soy/md-configure.soy?at=master

atlassian-plugin.xml:
https://bitbucket.org/dvdsmpsn/markdown-for-confluence/src/6f97807fc7abc919cb325dc3e1a2d0e8b12c884c/src/main/resources/atlassian-plugin.xml?at=master#cl-65

In the plugin xml file look at the following (I've stripped out the bits that aren't for the config page):

<?xml version="1.0" encoding="UTF-8"?>

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
  <plugin-info>
    ...
	...
    <param name="configure.url">/plugins/servlet/markdown-for-confluence/configure</param><-- the link in the UPM -->
  </plugin-info>
  
  ...
  ...

  <!-- the servelet -->
  <servlet name="Configuration Servlet" i18n-name-key="configuration-servlet.name" key="configuration-servlet" class="me.davidsimpson.confluence.addon.markdown.servlet.ConfigurationServlet">
    <description key="configuration-servlet.description">The Configuration Servlet Plugin</description>
    <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.ConfluenceAdministratorCondition" />
    <url-pattern>/markdown-for-confluence/configure</url-pattern>
  </servlet>

  <!-- soy template for the servlet -->
  <web-resource key="configure-soy">
    <transformation extension="soy">
      <transformer key="soyTransformer"/>
    </transformation>
    <resource type="download" name="md-configure.js" location="soy/md-configure.soy"/>
  </web-resource>

  <!-- link in the left hand navigation of the confluence admin section -->
  <web-item key="markdown-for-confluence.configure" name="Markdown Configure Link" weight="10000" section="system.admin/configuration">
    <description>Link to configure action</description>
    <label key="me.davidsimpson.confluence.addon.markdown-for-confluence.configure.web-item"/>
    <link>/plugins/servlet/markdown-for-confluence/configure</link>
    <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.ConfluenceAdministratorCondition" />
  </web-item>

  <!-- Some plumbing to help out -->
  <component-import key="loginUriProvider" interface="com.atlassian.sal.api.auth.LoginUriProvider"/>
  <component-import key="pluginSettingsFactory" interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory"/>
  <component-import key="soyTemplateRenderer" interface="com.atlassian.soy.renderer.SoyTemplateRenderer"/>
  <component-import key="templateRenderer" interface="com.atlassian.templaterenderer.TemplateRenderer"/>

  ...
  ...
  
</atlassian-plugin>

Traditionally people used velocity for configuration screens, but servlets + Soy means that you can use the same kind of code in Confluence, JIRA and other add-ons, so it's quite nice.


Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

7,071 views 6 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you