Script Fragments

Using ScriptRunner, you can customize the web UI through dynamically adding web fragments. See the Atlassian documentation on web fragments for Confluence.

You can use web fragments to:

  • Show an announcement banner

  • Show different banners for admins, non-admins, and users who are not logged in

  • Add buttons to the Tools menu for particular pages

This is accomplished by adding a UI customization at Administrator > Fragments.


There are several different types of fragment scripts available:

  • Web Item - A link or button that appears in your chosen location.

  • Web Panel - Displays additional information in a panel.

  • Web Section - Defines new locations to add items.

  • Web Resource - Defines custom JavaScript and CSS resources in specific contexts.

  • Hide UI Element - Hide any system web item or panel, including ones provided by plugins.

  • XML Module Item - Work around limitations from plugins.

As always, test in a development environment before deploying to your production environment.

Using Web Fragments

You can add, execute, edit, and delete the scripts from Administrator > Fragments. After restarting your instance, the UI customisations are in place. Some scripts are reloaded automatically, but you can edit the script item and click update if they are not.

All of the built-in scripts produce XML that is similar, but not interchangeable with, XML found in a plugin descriptor. You will notice that, for usability reasons, the forms do not provide all the possible configuration elements available in plugins. For example, the web item script does not give you the option to provide a tooltip for the web item link, a velocity context provider, or an icon URL.

You can work around this limitation using the Raw XML Module script.

Fragment Locator

Finding the locations and/or sections for web items, web sections, and web panels can be difficult. The Fragment Locator tool is designed to show you the places where you can put these fragments. You can enable (and disable) it from the main Fragments page.

Enabling the Fragment Locator changes the UI appearance for every user, so it should not be enabled in a production system.

Script Fragment Variables

The variables available to you depends on the fragment location. The Fragment Locator tool can help you see which variables are available, so your scripts run as expected.

Fragment binding variables are context-specific and knowing what is available in certain contexts could help you avoid unexpected scripting errors. After enabling the Fragment Locator, you can hover over a fragment to view available binding variables for an item or panel in a specific context.

For an example the following two screenshots are for Panel: location:servicedesk.portal.header in two different locations.

From the screenshots we can see variables such as serviceDesk, portal, or user are available in the Customer Portal window, but only the user binding variable is available in the User Profile window.

Browse Script Fragment Functionality

You can use the Search ScriptRunner Functionality search bar to search the available script fragments.

For example, if you’re looking for a script fragment that works with web items, you could type "web items" and press Enter. Then, the list of script fragments is narrowed down to only those containing the word "web items" in their title or description.