|
| 1 | +--- |
| 2 | +title: How to create components for Strapi plugins |
| 3 | +description: Learn how to create and configure components for your Strapi plugins |
| 4 | +sidebar_label: Create components for plugins |
| 5 | +displayed_sidebar: devDocsSidebar |
| 6 | +tags: |
| 7 | +- admin panel |
| 8 | +- components |
| 9 | +- content-type |
| 10 | +- guides |
| 11 | +- plugins |
| 12 | +- plugins development guides |
| 13 | +--- |
| 14 | + |
| 15 | +# How to create components for Strapi plugins |
| 16 | + |
| 17 | +When [developing a Strapi plugin](/dev-docs/plugins/developing-plugins), you might want to create reusable components for your plugin. Components in Strapi are reusable data structures that can be used across different content-types. |
| 18 | + |
| 19 | +To create components for your Strapi plugin, you'll need to follow a similar approach to creating content-types, but with some specific differences. |
| 20 | + |
| 21 | +## Creating components |
| 22 | + |
| 23 | +You can create components for your plugins in 2 different ways: using the Content-Type Builder (recommended way) or manually. |
| 24 | + |
| 25 | +### Using the Content-Type Builder |
| 26 | + |
| 27 | +The recommended way to create components for your plugin is through the Content-Type Builder in the admin panel. |
| 28 | +The [Content-Type Builder documentation](/user-docs/content-type-builder/creating-new-content-type#creating-a-new-component) provides more details on this process. |
| 29 | + |
| 30 | +### Creating components manually |
| 31 | + |
| 32 | +If you prefer to create components manually, you'll need to: |
| 33 | + |
| 34 | +1. Create a component schema in your plugin's structure. |
| 35 | +2. Make sure the component is properly registered. |
| 36 | + |
| 37 | +Components for plugins should be placed in the appropriate directory within your plugin structure. You would typically create them within the server part of your plugin (see [plugin structure documentation](/dev-docs/plugins/development/plugin-structure)). |
| 38 | + |
| 39 | +For more detailed information about components in Strapi, you can refer to the [Model attributes documentation](https://docs.strapi.io/dev-docs/backend-customization/models#components-json). |
| 40 | + |
| 41 | +## Reviewing the component structure |
| 42 | + |
| 43 | +Components in Strapi follow the following format in their definition: |
| 44 | + |
| 45 | +```javascript title="/my-plugin/server/components/category/component-name.json" |
| 46 | +{ |
| 47 | + "attributes": { |
| 48 | + "myComponent": { |
| 49 | + "type": "component", |
| 50 | + "repeatable": true, |
| 51 | + "component": "category.componentName" |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +## Making components visible in the admin panel |
| 58 | + |
| 59 | +To ensure your plugin's components are visible in the admin panel, you need to set the appropriate `pluginOptions` in your component schema: |
| 60 | + |
| 61 | +```javascript {9-16} |
| 62 | +{ |
| 63 | + "kind": "collectionType", |
| 64 | + "collectionName": "my_plugin_components", |
| 65 | + "info": { |
| 66 | + "singularName": "my-plugin-component", |
| 67 | + "pluralName": "my-plugin-components", |
| 68 | + "displayName": "My Plugin Component" |
| 69 | + }, |
| 70 | + "pluginOptions": { |
| 71 | + "content-manager": { |
| 72 | + "visible": true |
| 73 | + }, |
| 74 | + "content-type-builder": { |
| 75 | + "visible": true |
| 76 | + } |
| 77 | + }, |
| 78 | + "attributes": { |
| 79 | + "name": { |
| 80 | + "type": "string" |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +This configuration ensures your components will be visible and editable in both the Content-Type Builder and Content Manager. |
0 commit comments