Plugin concepts
Plugin concepts for Built.js themes and plugins.
Plugins can add new functionality or extend existing functionality for your site. A plugin will be included in a theme as a module. It includes all the pages, sections, content types and other data and functionality to fulfill a use case. For example, a "blog" plugin could be included in a theme, and this would allow a user to view a page that has a list of blog entries, a blog article page, and more. A Built.js plugin, from a technical point of view, is very similar to a theme in the following ways:
- It is a Next.js project
- It is defined with data files
- It requires a namespace
It differs from a theme because:
- It only has one module (but, like a theme's main modules, this module can have submodules)
Here is an example:
Code: https://github.com/richjava/blog-basic
Demo: https://builtjs-plugin-blog-basic.vercel.app/
Plugin namespace
A plugin needs a namespace (which is a short string) so that it doesn't have naming conflicts with the hosting theme and other plugins used in the theme. A namespace follows this naming convention:
- owner
- repo name
[owner]_[repo-name]
This namespace will be used in the plugin project in the path of:
- components
- api
- styles
So instead of components being located at
components/templates
they should be made available atcomponents/plugins/[plugin-name]/templates
. Similarly, api routes should be atpages/api/plugins/[api-name]
. For example, in the "richjava_blog" plugin, for a React component that is located atcomponents/plugins/richjava_blog/templates/lists/list2/list2.tsx
, when the end user of the theme exports it, the "List2" component is built into the home page of the site asGhRichjavaBlogList2
, like this:
Developing a plugin
A plugin is built in isolation from a theme. When ready, you can publish the plugin into the Built.js Studio the same way you would a theme: npx create-built-app publish
.
Once you have published the plugin, you can include it in a new or existing theme.
Adding your plugin to a new theme
If you are creating a theme through the Theme Designer in the Built.js Studio, after you have published your theme to the studio, you will be able to find it in the Theme Designer under "Plugins". From there you can can select your plugin to add it to your theme.
Adding your plugin to an existing theme
To add a plugin to a theme that you already have in the Built.js Studio, you can add it to the project's theme.json
file like this: