Користувацькі типи контенту в Strapi
Типи контенту в Strapi бувають трьох видів: Collection Type (список записів), Single Type (одна запис — налаштування сайту, домашня сторінка), Component (переиспользуемо група полів). Усі описуються JSON-схемою у src/api/ або src/components/.
Collection Type
// src/api/product/content-types/product/schema.json
{
"kind": "collectionType",
"collectionName": "products",
"info": {
"singularName": "product",
"pluralName": "products",
"displayName": "Товар"
},
"options": { "draftAndPublish": true },
"pluginOptions": { "i18n": { "localized": true } },
"attributes": {
"name": {
"type": "string",
"required": true,
"pluginOptions": { "i18n": { "localized": true } }
},
"slug": { "type": "uid", "targetField": "name" },
"description": {
"type": "richtext",
"pluginOptions": { "i18n": { "localized": true } }
},
"price": { "type": "decimal", "required": true, "min": 0 },
"stock": { "type": "integer", "default": 0, "min": 0 },
"images": { "type": "media", "multiple": true, "allowedTypes": ["images"] },
"category": {
"type": "relation",
"relation": "manyToOne",
"target": "api::category.category",
"inversedBy": "products"
},
"specs": {
"type": "component",
"repeatable": true,
"component": "product.spec"
}
}
}
Single Type
// src/api/homepage/content-types/homepage/schema.json
{
"kind": "singleType",
"collectionName": "homepages",
"info": {
"singularName": "homepage",
"pluralName": "homepages",
"displayName": "Домашня сторінка"
},
"attributes": {
"hero": { "type": "component", "component": "sections.hero", "repeatable": false },
"sections": { "type": "dynamiczone", "components": ["sections.text", "sections.gallery", "sections.cta"] },
"seo": { "type": "component", "component": "shared.seo", "repeatable": false }
}
}
Component
// src/components/shared/seo.json
{
"collectionName": "components_shared_seos",
"info": { "displayName": "SEO", "icon": "search" },
"attributes": {
"metaTitle": { "type": "string", "maxLength": 60 },
"metaDescription": { "type": "text", "maxLength": 160 },
"ogImage": { "type": "media", "multiple": false, "allowedTypes": ["images"] },
"noIndex": { "type": "boolean", "default": false }
}
}
API-запити до типів контенту
# Collection Type
GET /api/products?populate=images,category,specs&sort=createdAt:desc
# Single Type
GET /api/homepage?populate=hero,sections,seo
# Dynamic Zone — потрібно populate кожного компонента
GET /api/homepage?populate[sections][populate]=*
Програмне створення записів
// У контролері або сервісі Strapi
await strapi.entityService.create('api::product.product', {
data: {
name: 'Новий товар',
slug: 'new-product',
price: 1500,
publishedAt: new Date(),
},
})
Терміни
Створення 3–5 типів контенту з компонентами через Content-Type Builder та JSON займає 1–2 дні.







