What you'll learn
  • how to create a custom page Builder element
  • how to register plugins in Webiny applications

The full code example used in this article is available in our webiny-examplesexternal link GitHub repository.


Out of the box, Webiny’s Page Builder app provides a plethora of ready-made page elements we can use to create both simple and complex pages for our website. Furthermore, on top of the default set, users can also create their custom page elements, which is what this article demonstrates.

In this short article, we create a relatively simple page element that allows users to show a list of different SpaceXexternal link rocket and dragon spacecrafts. Here’s what the final result will look like:

SpaceX Page ElementSpaceX Page Element
(click to enlarge)

The custom page element will be available from the Media page elements category:

SpaceX Page Element in the Elements Menu (Media category)SpaceX Page Element in the Elements Menu (Media category)
(click to enlarge)

Also, upon dropping the element onto a page, users will have the ability to adjust the following three settings:

  1. type of spacecrafts to be displayed (rockets or dragons)
  2. number of spacecrafts to be displayed
  3. pagination offset (number of spacecrafts we want to skip when retrieving the data)
SpaceX Page Element in the Elements Menu (Media category)SpaceX Page Element in the Elements Menu (Media category)
(click to enlarge)

Note that the spacecrafts data will be retrieved from a non-official public SpaceX GraphQL HTTP API, located at https://spacex-production.up.railway.app/external link. Meaning, changing these settings will dictate the variables that will be included in GraphQL queries issued by the page element. More on this in the following sections.

Getting Started

Renderer React Component

To create a custom page element, we first need to create a renderer React componentexternal link which, as the name itself suggests, renders it. As we’ll be able to see, this is easily achieved via the createRendererexternal link factory function.


Via a couple of plugins, the next step is registering the renderer React component within our project’s Admin and Website apps.

In case you missed it, the Admin and Website apps are located in the apps/admin and apps/website folders of an existing Webiny project.

On the Admin app side, we first register the PbEditorPageElementPluginexternal link plugin, which enables us to introduce our custom page element into the Page Builder’s page editor and enables users to drop the new element onto a page.

After that, optionally, we register the PbEditorPageElementAdvancedSettingsPluginexternal link plugin, which lets us define all the related settings that are available to users upon dropping the page element onto a page. Since the page element we’re building does contain settings that the user can adjust, we will need this plugin as well.

When it comes to the Website app, here we register the PbRenderElementPluginexternal link plugin. With it, we ensure our renderer React component is utilized upon serving a published page to an actual website visitor. Note we’ll also need this plugin on the Admin app side because previewing pages is possible there too, outside the page editor.

Page Preview In the Admin AppPage Preview In the Admin App
(click to enlarge)

Code Organization

There are multiple approaches when it comes to where to place our custom page element code. In this tutorial, we will be placing all the code in the apps/themeexternal link folder. More specifically, we’ll create a new apps/theme/pageElementsexternal link folder, and inside it, the new apps/theme/pageElements/spaceXexternal link folder.

The apps/theme/pageElementsexternal link folder can be further used as a folder for all of your custom page elements.

Overview of Files

Ultimately, in the apps/theme/pageElements/spaceXexternal link folder, we’ll end up with the following three files:

  1. SpaceX.tsxexternal link - contains the renderer React component
  2. admin.tsxexternal link - contains the Admin app plugins
  3. website.tsexternal link - contains the Website app plugin

Useful Webiny CLI Commands

For easier development, both Admin and Website apps can be run and developed locally. This is done via the following two webiny watch commands:
yarn webiny watch admin --env YOUR_ENV
yarn webiny watch website --env YOUR_ENV

If needed, both commands can be run at the same time, via two separate terminal sessions.


Renderer React Component

As previously mentioned, in order to create a custom page element, we start off by creating a new renderer React component. We create the apps/theme/pageElements/spaceX/SpaceX.tsxexternal link file with the following code:

import React, { useEffect, useState } from "react";
import { request } from "graphql-request";
import { createRenderer, useRenderer } from "@webiny/app-page-builder-elements";

// For simplicity, we're hard-coding the GraphQL HTTP API URL here.
const GQL_API_URL = "https://spacex-production.up.railway.app/";

// These are the necessary GraphQL queries we'll need in order to retrieve data.
const QUERIES = {
  rockets: /* GraphQL */ `
    query listRockets($limit: Int, $offset: Int) {
      data: rockets(limit: $limit, offset: $offset) {
  dragons: /* GraphQL */ `
    query listDragons($limit: Int, $offset: Int) {
      data: dragons(limit: $limit, offset: $offset) {

export interface Spacecraft {
  id: string;
  name: string;
  description: string;
  wikipedia: string;

// It's often useful to type the data that the page element will carry.
export interface SpaceXElementData {
  variables: {
    limit: string;
    offset: string;
    type: "rockets" | "dragons";

// The renderer React component.
export const SpaceX = createRenderer(() => {
  // Let's retrieve the variables that were chosen by
  // the user upon dropping the page element onto the page.
  const { getElement } = useRenderer();
  const element = getElement<SpaceXElementData>();
  const { limit, offset, type } = element.data.variables;

  const [data, setData] = useState<Spacecraft[]>([]);

  // This is where we fetch the data and store it into component's state.
  useEffect(() => {
    request(GQL_API_URL, QUERIES[type], {
      limit: parseInt(limit),
      offset: parseInt(offset)
    }).then(({ data }) => setData(data));
  }, [limit, offset, type]);

  if (!data.length) {
    return <>Nothing to show.</>;

  // If the data has been retrieved, we render it via a simple unordered list.
  return (
      {data.map(item => (
        <li key={item.id}>
          <br />
            More info at&nbsp;
            <a href={item.wikipedia} target={"_blank"} rel={"noreferrer"}>

Note that, for simplicity’s sake, all the code is placed in a single file. Of course, it is possible to organize it across multiple files, if preferred.

Furthermore, in order to be able to issue remote GraphQL queries, we introduce the graphql-requestexternal link package. The package can be installed via the following command, run from your project root:

yarn workspace theme add graphql-request

With this code in place, we’re ready for the next step, which is registering the renderer React component within our Admin and Website apps. We’ll start with the Website app, as the plugin that we’ll create here will also be needed within the Admin app.

Website App

As previously mentioned, ensuring our custom renderer React component is actually used upon rendering a published page is done via the PbRenderElementPluginexternal link plugin. For this, we’ll create a new apps/theme/pageElements/spaceX/website.tsexternal link file with the following code:

import { PbRenderElementPlugin } from "@webiny/app-page-builder/types";
import { SpaceX } from "./SpaceX";

const plugin = {
  name: "pb-render-page-element-space-x",
  type: "pb-render-page-element",
  elementType: "spaceX",
  render: SpaceX
} as PbRenderElementPlugin;

export default plugin;

With this plugin in place, we need to register it within the Website app. This can be achieved via the apps/website/src/plugins/pageBuilder.tsexternal link file:

// The rest of code was removed for brevity.import spaceX from "theme/pageElements/spaceX/website";
// ...
export default [  // ...  spaceX  // ...];

With the plugin registered, we’re ready to move on to the next step, and that is the Admin app.

Admin App

As previously mentioned, within the Admin app, we need two plugins: PbEditorPageElementPluginexternal link and PbEditorPageElementAdvancedSettingsPluginexternal link.

For simplicity’s sake, we’ll again place all the code in a single file, this time in apps/theme/pageElements/spaceX/admin.tsxexternal link:

import React from "react";
import { validation } from "@webiny/validation";
import { Input } from "@webiny/ui/Input";
import { ButtonPrimary } from "@webiny/ui/Button";
import { Cell, Grid } from "@webiny/ui/Grid";
import { Select } from "@webiny/ui/Select";
import {
} from "@webiny/app-page-builder/types";

import { SpaceX, SpaceXElementData } from "./SpaceX";

const INITIAL_ELEMENT_DATA: SpaceXElementData = {
  variables: { type: "rockets", limit: "10", offset: "0" }

export default [
  // The `PbEditorPageElementPlugin` plugin.
    name: "pb-editor-page-element-space-x",
    type: "pb-editor-page-element",
    elementType: "spaceX",
    render: SpaceX,
    toolbar: {
      // We use `pb-editor-element-group-media` to put our new
      // page element into the Media group in the left sidebar.
      title: "SpaceX",
      group: "pb-editor-element-group-media",
      preview() {
        // We can return any JSX / React code here. To keep it
        // simple, we are simply returning the element's name.
        return <>Space X Page Element</>;

    // Defines which types of element settings are available to the user.
    settings: [

    // Defines onto which existing elements our element can be dropped.
    // In most cases, using `["cell", "block"]` will suffice.
    target: ["cell", "block"],
    onCreate: "open-settings",

    // `create` function creates the initial data for the page element.
    create(options) {
      return {
        type: "spaceX",
        elements: [],
  } as PbEditorPageElementPlugin,

  // The `PbEditorPageElementAdvancedSettingsPlugin` plugin.
    name: "pb-editor-page-element-advanced-settings-space-x",
    type: "pb-editor-page-element-advanced-settings",
    elementType: "spaceX",
    render({ Bind, submit }) {
      // In order to construct the settings form, we're using the
      // `@webiny/form`, `@webiny/ui`, and `@webiny/validation` packages.
      return (
            <Cell span={12}>
              <Bind name={"variables.type"}>
                <Select label={"Type"} description={"Chose the record type you want to query."}>
                  <option value="rockets">Rockets</option>
                  <option value="dragons">Dragons</option>
            <Cell span={12}>
                  description={"Number of records to be returned."}
            <Cell span={12}>
                  description={"Amount of records to be skipped."}
            <Cell span={12}>
              <ButtonPrimary onClick={submit}>Save</ButtonPrimary>
  } as PbEditorPageElementAdvancedSettingsPlugin

Before we register these plugins, note that, in order to construct the settings form, we’re using the @webiny/formexternal link, @webiny/uiexternal link, and @webiny/validationexternal link packages. Since the @webiny/uiexternal link is not installed within the apps/themeexternal link package by default, we need to install it. This can be done via the following command, run from your project root:

yarn workspace theme add @webiny/ui

When it comes to plugin registration, in total, there are three plugins we need to register within the Admin app. The two shown above, plus the previously created PbRenderElementPluginexternal link plugin. The PbRenderElementPluginexternal link is required because, as mentioned, pages can also be previewed within the Admin app, outside the page editor.

Page Preview In the Admin AppPage Preview In the Admin App
(click to enlarge)

We register the two plugins via the apps/admin/src/plugins/pageBuilder/editorPlugins.tsexternal link file:

// Some of the code was removed for brevity.import spaceX from "theme/pageElements/spaceX/admin";
// ...
export default [  // ...  spaceX  // ...];

The PbRenderElementPluginexternal link plugin can be registered via the apps/admin/src/plugins/pageBuilder/renderPlugins.tsexternal link file:

// The rest of code was removed for brevity.import spaceX from "theme/pageElements/spaceX/website";
// ...
export default [  // ...  spaceX  // ...];

With all the plugins registered, we’re now ready to give this a try locally in our browser.


With the above steps correctly completed, we should be able to see our custom page element in Page Builder’s page editor and be able to drop it onto a page. The page element should also be correctly rendered when previewing the page, and also on the public website, once the page has been published.


Creating custom page elements is certainly an interesting option when users need more than what the default set of page elements provides.

On the code level, this could be creating completely custom (renderer) React components, including needed external NPM libraries, or even issuing remote HTTP requests to external HTTP APIs in order to retrieve data from standalone external systems.

On the other hand, custom page elements also add additional flexibility by allowing content creators to tweak elements’ settings and, ultimately, allowing them to achieve more with just a single page element.

Additional Examples