Through plugins it is possible to enrich the functionalities of DatoCMS by adding new pages and sections to the standard interface. These pages are almost full-screen, 100% customisable, and the end-user can reach them through links/menu items that can be added to the different DatoCMS navigation menus.
For example, the Custom Page plugin lets you embed any external URL inside DatoCMS, while the Content Calendar plugin uses a custom page to explore your records inside a calendar:
A page is nothing more than an iframe, inside of which the plugin developer can render what they prefer, while also having the possibility to:
access a series of information related to the project in which the plugin is installed or the logged-in user;
make calls to DatoCMS to produce various effects and interacting with the main application (ie. navigate to other pages, trigger notifications, opening modals, etc.);
Adding a link to the custom page
The SDK provides a number of hooks for adding links to custom pages within the navigation menus of DatoCMS.
Top-bar navigation items
To add one or more tabs to the top bar of the interface, you can use the mainNavigationTabs hook:
The pageId property is crucial here, as it specifies which custom page you want to display when you click the tab. If you wish, you can also customize the insertion point of the menu item via the placement property:
{
// ...other properties
placement:['before','content'],
}
In this case, we are asking to show the tab before the default "Content" tab.
As for the icon, you can either use one of the Awesome 5 Pro solid icons by their name, or explicitly pass a custom SVG:
In this example, it can be seen that it is possible to show (or not) menu items depending on the logged-in user's permissions, or to show labels translated into the user's preferred interface language.
Step 2: Rendering the page
Once you enter the page through one of the links, you can render the content of the custom pages by implementing the renderPage hook:
The strategy to adopt here is is to implement a switch that, depending on the pageId, will render a different, specialized React component.
The hook, in its second ctx argument, provides a series of information and methods for interacting with the main application. It is a good idea to pass it to the page component, in the form of a React prop.
Here's an example page component. It is important to wrap the content inside the Canvas component to give our app the look and feel of the DatoCMS web app:
import{RenderPageCtx}from'datocms-plugin-sdk';
import{Canvas}from'datocms-react-ui';
typePropTypes={
ctx:RenderPageCtx,
};
functionWelcomePage({ ctx }: PropTypes){
return(
<Canvasctx={ctx}>
Hi there!
</Canvas>
);
}
Function Reference
mainNavigationTabs()
Use this function to declare new tabs you want to add in the top-bar of the
UI.
Return value
The function must return an array of objects with the following structure:
Properties available in context
The following information and methods are available:
settingsAreaSidebarItemGroups()
Use this function to declare new navigation sections in the Settings Area
sidebar.
Return value
The function must return an array of objects with the following structure:
Properties available in context
The following information and methods are available:
contentAreaSidebarItems()
Use this function to declare new navigation items in the Content Area
sidebar.
Return value
The function must return an array of objects with the following structure:
Properties available in context
The following information and methods are available:
renderPage()
This function will be called when the plugin needs to render a specific
page (see the mainNavigationTabs, settingsAreaSidebarItemGroups and
contentAreaSidebarItems functions).
Properties available in context
The following information and methods are available:
Methods available in context
The following information and methods are available: