Last updated Oct 3, 2024

Writing an space index page for a content type

Applicable:

This tutorial applies to Confluence 5.0.

Level of experience:

This is an intermediate tutorial. You should have completed at least one beginner tutorial before working through this tutorial. See the list of developer tutorials.

If your plugin provides another content type than Pages or Blog, it is probably useful to build an index page for it.

This tutorial isn't about Blueprints

Index pages are created automatically for Blueprints.

Example: A Space Admin creates a template, then a user presses Create and chooses the template. The template is created and its parent page is an Index Page.

Templates do not generate a custom content type: They are simple Pages. As opposed to this, a plugin managing room reservations could want to display an index page for the bookings. In our example, we will name it "Custom Content".

Preparation

The example below is available on the following BitBucket repository:

bitbucket.org/atlassian_tutorial/space-plugin-example

You need to create a Confluence plugin and update the version of Confluence to 5.0-beta5.

The link in the sidebar can be declared in atlassian-plugin.xml:

atlassian-plugin.xml

1
2
<web-item key="plugin-content-main-link" name="Plugin Content" section="system.space.sidebar/main-links" weight="30">
    <label key="plugin.content.title"/>
    <link id="plugin-content-main-link-id">/plugins/${project.artifactId}/view-custom-content.action?key=$generalUtil.urlEncode($helper.spaceKey)</link>
    <styleClass>plugin-content-main-link</styleClass>
</web-item>

Creating an action

The link declared above needs to lead to the index page:

1
2
<struts name="Example Actions" key="example-actions">
    <description>Examples of actions</description>
    <package name="space-links-struts-package" extends="default" namespace="/plugins/unique/value">
        <default-interceptor-ref name="validatingStack"/>
        <action name="view-custom-content" class="com.atlassian.examples.MyAction" method="doViewCustomContent">
            <result name="input" type="velocity">/templates/view-custom-content.vm</result>
        </action>
    </package>
</struts>
1
2
public class MyAction extends AbstractSpaceAction
{
    public String doViewCustomContent()
    {
        return INPUT;
    }
}

Writing the index page

view-custom-content.vm

1
2
<html>
    <head>
        <title>$action.getText("plugin.content.title")</title>
        <meta name="decorator" content="main"/>
    </head>

    #applyDecorator("root")
        #decoratorParam("context" "space")
        #decoratorParam("mode" "collector")
        #decoratorParam("collector-key" "plugin-content-main-link") ## Highlights the link in the sidebar
        <body>
            <p>Place custom content rendering here.</p>
            <p>
                <a href="$req.contextPath/plugins/space-links/add-link.action?key=${space.key}">Go to the Space Tools screen</a>
            </p>
        </body>
    #end
</html> 

Result

You can see the link in the sidebar next to Pages and Blog, and the index page on the right.

Known Bug: Gray header

The header is gray on Confluence 5.0-beta5. If you use #decoratorParam("mode" "collector") in the template, the header will automatically come with the right color in Confluence 5.0. If you need to use another mode, add this declaration to your css:

1
2
.(your-own-mode)-mode.spacetools.with-space-sidebar #main-header {
    background-color: transparent;
}

Rate this page: