This tutorial will walk you through creating your first Forge app for Confluence using UI Kit.
The Hello World Confluence Space Page App is designed to show you the basics of building a Forge app for Confluence.
Approximate time needed: 15-30 minutes
Suggested Skills: Basic understanding of Javascript, React is recommended.
First, you'll use the Forge CLI to create a new app based on one of the many available templates, you will then customise the app and add a new module. You will also learn how to build and deploy the app, and install it onto your confluence developer test site.
Next, you'll customise your app further by accessing application context data via both the front and back end. You will also learn how to automatically deploy the app, and troubleshoot the app using console logging.
Finally, you'll personalise your app by replacing 'world' with the name of the current user in Confluence, which you will get from the Confluence API. You'll also learn how to use the Forge CLI to automatically detect and fix permissions errors.
Along the way, you'll find extra tips, links and resources that will allow you to learn more about what was covered in each section, and become familiar with how resources are laid out in the Forge documentation.
Before you start creating your app, ensure you've prepared by completing the steps outlined in Preparing for your first quest.
This page describes a Forge preview feature. Preview features are deemed stable; however, they remain under active development and may be subject to shorter deprecation windows. Preview features are suitable for early adopters in production environments.
If you have time, you may also want to review Essential Knowlege which will explain where to find all the essential forge knowledge, and more importantly where to go to ask for help if you get stuck.
Create an app based on the Confluence macro template.
Navigate to the directory where you want to create the app. A new subdirectory with the app's name will be created there.
Create your app by running:
1 2forge create
Enter a name for your app (up to 50 characters). For example my-first-quest.
When prompted to Select a category, choose UI kit.
Select Confluence
as the product using the arrow keys and press the enter key.
Select the confluence-space-page template.
Change to the app subdirectory to see the app files:
1 2cd my-first-quest
The forge create
command is part of the Forge CLI. The CLI provides a range of functionality for managing and working with your forge app. You can find the Forge CLI documentation at https://developer.atlassian.com/platform/forge/cli-reference/
The app we'll create will create a Confluence Space Page, which will appear as a link in the space navigation menu.
The confluence-space-page
template uses Node.js and has the following structure:
1 2. ├── README.md ├── manifest.yml ├── package-lock.json ├── package.json └── src └── frontend // front-end code goes in this folder └── index.jsx └── resolvers // back-end code goes in this folder └── index.js └── index.js // this exports the resolver functions to the top level directory
Lets have a look at these files and directories a little more closely:
src/frontend/index.jsx
: contains the application the user interacts with directlymanifest.yml
: contains the description of your app, including the name and ID of the app, the app permissions, and the modules the app uses. To learn more about the manifest.yml file, see Forge manifest documentation.package.json
: contains the app’s Node.js metadata. See the Node documentation for more information.package-lock.json
: Records the version of the app’s dependencies.README.md
: contains information about the app. We recommend updating this as you change the behavior of the app.src/resolvers/index.js
: contains the applications backend functions, the functions are then defined in index.js
and can be invoked from the frontend using the UI bridge method. For more information, see Custom UI Resolver docs.index.js
: Where you write the src/resolvers/index.js
function definitions. For more information, see Custom UI Resolver docs.This app displays content in place of a Confluence page within a Confluence space. The app appears as a link in the space navigation menu, and the title of each module is used as the title of the link, with the app rendering inside the content area of Confluence.
To learn more about the confluence space page module, you can consult the Forge reference docs at https://developer.atlassian.com/platform/forge/manifest-reference/modules/confluence-space-page/
manifest.yml
file.title
entry under the confluence:spacePage
module.title
to <your name>'s first quest
. For example, Charlie's first quest.Your manifest.yml
file should look like the following, with your values for the title and app ID:
1 2modules: confluence:spacePage: - key: my-first-quest-hello-world-space-page resource: main resolver: function: resolver render: native title: Charlie's first quest route: hello-world function: - key: resolver handler: index.handler resources: - key: main path: src/frontend/index.jsx app: id: '<your app id>'
You may notice that the module in the manifest includes a render: native
property. This is how you declare that a module is a UI Kit app.
You must include the render: native
property for any other UI Kit modules you may wish to add.
To use your app, it must be installed onto an Atlassian site. The forge deploy
command builds, compiles, and deploys your code; it'll also report any compilation errors. The forge install
command then installs the deployed app onto an Atlassian site with the required API access.
1 2forge deploy
1 2forge install
confluence
using the arrow keys and press the enter key.Once the install complete message appears, your app is installed and ready to use on the site spevccified. You can delete your app from the site by running the forge uninstall
command.
Once your app is installed, it will automatically pick up all minor app deployments so you don't need to run forge install
every time you make a change. Minor deployments are changes that don't modify the app permissions in the manifest.yml
file.
To deploy minor changes to your developer site, or bitbucket workspace run the forge deploy
command.
The Forge CLI will also detect if a change has been made to your app to modify the apps permissions, and will direct you to update your app installation using the forge install --upgrade
command.
Running the forge install
command only installs your app onto the selected product. To install onto multiple products, repeat these steps again, selecting another product each time. Note that the Atlassian Marketplace does not support cross-product apps yet.
You must run forge deploy
before running forge install
in any of the Forge environments.
Now that your app is installed, it's time to see it in action in your Confluence site.
When you navigate to your app in Confluence, you'll see that it displays the message Hello World!
followed by another line of text which says Loading...
and then changes to read Hello World!
as well. The first Hello World!
and the Loading...
text are defined within the src/frontend/index.jsx
file - this file is calling a resolver function in the back end of the app, where the second Hello World!
message is defined.
In this section, you'll make some changes to the src/frontend/index.jsx
to change the appearance of your app by using an additional UI Kit component.
Navigate to the src/frontend
directory.
Open the index.jsx
file. The default content of the file is shown below:
1 2import React, { useEffect, useState } from 'react'; import ForgeReconciler, { Text } from '@forge/react'; import { invoke } from '@forge/bridge'; const App = () => { const [data, setData] = useState(null); useEffect(() => { invoke('getText', { example: 'my-invoke-variable' }).then(setData); }, []); return ( <> <Text>Hello world!</Text> <Text>{data ? data : 'Loading...'}</Text> </> ); }; ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> );
Modify the import statement on line 2 of index.jsx
to import the heading component,
1 2import ForgeReconciler, { Heading, Text } from '@forge/react';
Modify the App return statement to use the <Heading>
tags instead of the <Text>
tags on line 14, so that Hello world!
displays as a medium sized heading,
1 2<Heading as="h1">Hello world!</Heading>
To learn more about the Heading component, you can consult the Forge UI Kit reference docs at https://developer.atlassian.com/platform/forge/ui-kit/components/heading/
Save the changes you made to index.jsx
.
Navigate back to the app's top-level directory, and deploy your changes by running:
1 2forge deploy
Once the deployment is complete, refresh your app's space page in confluence to see the changes.
In the next part of this quest you will customise your app further by accessing application context data via both the front and back end. You will also learn how to automatically deploy your app, and troubleshoot it using console logging.
Rate this page: