Please take a look at our overview of how and why you should include Javascript and CSS resources into your plugin. The page below gives specific details of the Web Resource plugin module type.

Including your web resource in a specific context

In Confluence 2.10 we added the ability to specify web resources like CSS and JavaScript to be included in specific contexts of Confluence. Please see below for the currently available contexts and more information.

On this page:

[Unable to render {include} The included page could not be found. ({include} をレンダリングできません。ページが見つかりませんでした)] を選択し、

Web Resource Contexts

In Confluence 2.10 and later, you can automatically include web resources like CSS and JavaScript on all screens of a specific type in the application. These are called web resource contexts. The currently available contexts are:

コンテキスト

説明

main

Everywhere except administration screens

admin

Administration screens. Use with care because poorly formed CSS or JavaScript can prevent access to administer Confluence.

ダッシュボード

ダッシュボード

エディタ

Anywhere an editor appears (fixed in 3.1 to work in comment editor).

ページ

Any page-related screen like view, edit, attachments, info; but not blog post, space or global screens.

blogpost

Any blog-related screen like view, edit, attachments, info; not page, space or global screens.

スペース

Any space-related screen, like those found in the top section of the Browse menu.

Technical note: the 'page', 'blogpost' and 'space' contexts correspond to the usage of the 'page.vmd', 'blogpost.vmd' and 'space.vmd' decorators in Confluence.

To configure your web resource to be included for example in the 'space' and 'page' contexts you add <context> child elements to your <web-resource> element in your atlassian-plugin.xml:

<web-resource name="Resources" key="resources">
        <resource name="foo.js" type="download" location="resources/foo.js">
        </resource>
        <context>space</context>
        <context>page</context>
</web-resource>

Using web resource contexts allows you to provide plugins that dynamically create HTML using JavaScript on any page in Confluence. For example, the Content Navigation Plugin includes a snippet of JavaScript on every page in the application, which listens for a particular keyboard shortcut to open a little search box on top the Confluence UI.

Introducing new contexts

If your plugin adds a lot of screens to Confluence, it might be annoying to put many #requireResource() declarations in each Velocity template. An alternative is to introduce a new web resource context for your plugin which your plugin web resources (or any other plugin web resource) can hook into, to be automatically included on these screens.

To introduce a new context in your plugin Velocity templates, you can call the #requireResourcesForContext() Velocity macro:

#requireResourcesForContext("com.acme.plugin.fancy-context")

This will include any resource in the page that specifies a context like this in its definition: <context>com.acme.plugin.fancy-context</context>.

We recommend you namespace your new contexts in this way so as not to clash with any future contexts in Confluence or other plugins.

関連トピック

Adding Plugin and Module Resources
Including Javascript and CSS resources
Writing Confluence Plugins
Installing and Configuring Plugins Manually

Information sourced from Plugin Framework documentation

  • ラベルなし