Introduction
Define custom fields for your content without touching code.
đ¯ What does this module do?â
The AttributesSets module lets you use custom fields for your content (products, pages, forms, etc.) without hardcoding them in your application.
Think of it as a form builder for your data - you define what fields you need, and OneEntry handles the rest.
đ Simple Explanationâ
Imagine you're building an online store. Each product needs:
- Name (text)
- Price (number)
- Image (picture)
- Description (long text)
- Category (dropdown)
Instead of hardcoding these fields in your app, you use Attributes to define them in OneEntry admin panel. Then you can:
- â Add new fields anytime (no code changes!)
- â Reuse fields across different content types
- â Change field types without redeploying
- â Manage all content structure in one place
Real-world example:
Without Attributes (hardcoded):
- Code: const product = { name, price, image, description }
- To add "color" field â Change code, redeploy, wait â
With Attributes (dynamic):
- Admin panel: Add "color" attribute
- Code automatically includes new field â
- No deployment needed! â
⨠Key Conceptsâ
What is an Attribute?â
An attribute is a single field that stores data.
Examples:
- Product name (string)
- Product price (float)
- Product image (image)
- Publish date (date)
What is an Attribute Set?â
An attribute set is a collection of attributes that define a structure.
Example: Product Attribute Set
- name (string)
- price (float)
- description (text)
- images (group of images)
- category (list)
- inStock (integer)
Why Use Attribute Sets?â
| Without Attributes | With Attributes |
|---|---|
| â Hardcoded fields | â Dynamic fields |
| â Code changes needed | â Edit in admin panel |
| â Redeploy required | â Live updates |
| â Rigid structure | â Flexible structure |
| â Duplicate code | â Reusable sets |
đ What You Need to Knowâ
1. Three Important Termsâ
| Term | What It Is | Example |
|---|---|---|
| Marker | Unique code identifier | "product_name" |
| Type | What kind of data it stores | "string", "integer", "image" |
| Value | Attribute value | "Product Name" |
Important about Markers:
- Must be unique
- No spaces allowed (use
_instead) - Can't start with a number
- Use lowercase for consistency
Examples:
- â
Good:
product_name,price_usd,main_image - â Bad:
product name,2nd_price,Product Name
2. Reusabilityâ
Attribute sets can be reused across different entities:
"Basic Info" Attribute Set:
- title (string)
- description (text)
- publish_date (date)
Used by:
â
Blog posts
â
News articles
â
Product pages
â
Event listings
Why this matters: Change once, updates everywhere!
đ Available Data Typesâ
Attributes can store different types of data. Choose the right type for each field.
Quick Reference Tableâ
| Type | Best For | Example Use |
|---|---|---|
| string | Short text | Product name, email |
| text | Long formatted text | Blog post, description |
| textWithHeader | Text with title | Article sections |
| integer | Whole numbers | Quantity, age |
| real | High-precision decimals | Scientific data |
| float | Decimal numbers | Price, rating |
| date | Just the date | Birth date, deadline |
| dateTime | Date + time | Event start, published at |
| time | Just the time | Opening hours |
| file | Any file | PDF, document |
| image | Single image | Avatar, logo |
| groupOfImages | Multiple images | Photo gallery |
| radioButton | Single choice | Size (S/M/L) |
| list | Dropdown selection | Country, category |
| entity | Link to other content | Related products |
| timeInterval | Date range | Promotion period |
| json | Custom structured data | API response |
đ Detailed Data Type Descriptionsâ
Text Typesâ
When to use what:
- string - Single line, under 255 characters (name, email, title)
- text - Multiple paragraphs, supports formatting (articles, descriptions)
- textWithHeader - Text that needs a headline (blog sections, FAQs)
Number Typesâ
When to use what:
- integer - No decimals needed (age, quantity, views)
- float - Standard decimals (price $19.99, rating 4.5)
- real - Extra precision needed (scientific calculations)
Date/Time Typesâ
When to use what:
- date - Just the day (birthday, deadline)
- time - Just the hour (business hours, appointment time)
- dateTime - Both needed (event start, article published)
- timeInterval - Period between dates (sale duration, vacation dates)
File & Image Typesâ
When to use what:
- file - Any document (PDF, DOC, ZIP)
- image - One picture (product photo, avatar)
- groupOfImages - Multiple pictures (gallery, product images)
Selection Typesâ
When to use what:
- radioButton - Pick only ONE option (Yes/No, Size S/M/L)
- list - Dropdown with options (Country, Category, Status)
Advanced Typesâ
- entity - Link to other pages/products (Related Items, Categories)
- json - Store complex data structures (API responses, settings)
đ Data Type Examplesâ
Below are technical examples of each data type's structure.
Click to see all data type examples
Data Types Referenceâ
Data types can be of the following types:
- String: Simple text, for example, "Hello, world!".
Example:
{
"type": "string",
"value": {},
"marker": "string",
"position": 1,
"listTitles": [],
"validators": {
"requiredValidator": {
"strict": true
}
},
"localizeInfos": {
"title": "String"
},
"additionalFields": [
{
"type": "integer",
"value": "10",
"marker": "Extra"
}
]
}
- Text: Longer text, often formatted, for example, an article or a letter.
Example:
{
"type": "text",
"value": {},
"marker": "text",
"position": 2,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Text"
},
"additionalFields": []
}
- Text with Header: Text with a header that can be used to denote a topic or category.
Example:
{
"type": "textWithHeader",
"value": {},
"marker": "text_with_header",
"position": 3,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Text With Header"
},
"additionalFields": []
}
- Integer: An integer, for example, 5, 100, -2.
Example:
{
"type": "integer",
"value": {},
"marker": "integer",
"position": 4,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Integer"
},
"additionalFields": []
}
- Real: The same as Float, but with higher precision.
Example:
{
"type": "real",
"value": {},
"marker": "real_number",
"position": 5,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Real Number"
},
"additionalFields": []
}
- Float: A data type for floating-point numbers that can have a decimal part, for example, 3.14, 1.5, -0.25.
Example:
{
"type": "float",
"value": {},
"marker": "float",
"position": 6,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Float"
},
"additionalFields": []
}
- Date and Time: A combination of date and time, for example, 2023-10-27 10:00:00.
Example:
{
"type": "dateTime",
"value": {},
"marker": "date_time",
"position": 7,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "DateTime"
},
"additionalFields": []
}
- Date: A date, for example, 2023-10-27.
Example:
{
"type": "date",
"value": {},
"marker": "date",
"position": 8,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Date"
},
"additionalFields": []
}
- Time: A time, for example, 10:00:00.
Example:
{
"type": "date",
"value": {},
"marker": "date",
"position": 8,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Date"
},
"additionalFields": []
}
- File: Any file on your computer, for example, a document, image, music.
Example:
{
"type": "file",
"value": {},
"marker": "file",
"position": 10,
"listTitles": [],
"validators": {
"checkingFilesValidator": {
"maxUnits": "kb",
"maxValue": "2000",
"minUnits": "kb",
"minValue": 0,
"extensions": []
}
},
"localizeInfos": {
"title": "File"
},
"additionalFields": []
}
- Image: An image, for example, a photograph, drawing.
Example:
{
"type": "image",
"value": {},
"marker": "image",
"position": 11,
"listTitles": [],
"validators": {
"sizeInPixelsValidator": {
"maxX": "500",
"maxY": "500"
}
},
"localizeInfos": {
"title": "Image"
},
"additionalFields": []
}
- Group of Images: A collection of images, for example, a photo album.
Example:
{
"type": "groupOfImages",
"value": {},
"marker": "image_group",
"position": 12,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Image Group"
},
"additionalFields": []
}
- Radio Button: A selection button from which only one option can be chosen.
Example:
{
"type": "radioButton",
"value": {},
"marker": "radio",
"position": 13,
"listTitles": [
{
"title": "A",
"value": "a",
"extended": {
"type": null,
"value": null
},
"position": 1
},
{
"title": "B",
"value": "b",
"extended": {
"type": null,
"value": null
},
"position": 2
}
],
"validators": {},
"localizeInfos": {
"title": "Radio"
},
"additionalFields": []
}
- List: A list of items, for example, a shopping list.
Example:
{
"type": "list",
"value": {},
"marker": "list",
"position": 14,
"listTitles": [
{
"title": "A",
"value": "a",
"extended": {
"type": null,
"value": null
},
"position": 1
},
{
"title": "B",
"value": "b",
"extended": {
"type": null,
"value": null
},
"position": 2
},
{
"title": "C",
"value": "c",
"extended": {
"type": "string",
"value": "Additional Value"
},
"position": 3
}
],
"validators": {},
"localizeInfos": {
"title": "List"
},
"additionalFields": []
}
- Entity: An entity representing an object.
Example:
{
"type": "entity",
"value": {},
"marker": "entity",
"position": 15,
"listTitles": [
{
"title": "Products",
"value": {
"id": 1,
"depth": 0,
"parentId": null,
"position": 1,
"selected": true
}
},
{
"title": "Normal Page",
"value": {
"id": 4,
"depth": 0,
"parentId": null,
"position": 2,
"selected": true
}
},
{
"title": "Error",
"value": {
"id": 2,
"depth": 0,
"parentId": null,
"position": 3,
"selected": true
}
}
],
"validators": {},
"localizeInfos": {
"title": "Entity"
},
"additionalFields": [
{
"type": "string",
"value": "Test Field",
"marker": "test_field"
}
]
}
- Time interval: A flexible calendar with a user-friendly interface for managing time interval data.
Example:
{
"type": "timeInterval",
"value": {},
"marker": "time_interval",
"position": 16,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Time Interval"
},
"additionalFields": []
}
- JSON: Some data in JSON format.
Example:
{
"type": "json",
"value": {},
"marker": "json",
"position": 17,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "Json"
},
"additionalFields": []
}
The content filling interface will correspond to the selected data type for each attribute field.
đĄ Important Notesâ
Validatorsâ
You can add validators for attributes to ensure data quality:
- Required fields
- Min/max length for text
- File size limits for uploads
- Pixel dimensions for images
- Date ranges
Learn more: See "Validators" section for detailed configuration.
Shared Attribute Setsâ
â ī¸ Important: If one attribute set is used by multiple entities, be careful when making changes:
Deleting an attribute:
- â Removes it everywhere the set is used
- â Deletes all content in that field
- â ī¸ Cannot be undone!
Adding an attribute:
- â Added everywhere the set is used
- â Existing content unchanged
- âšī¸ New field will be empty for existing items
Example:
"Product Info" used by:
- Physical Products
- Digital Products
- Services
Delete "weight" attribute â Removed from ALL three! â ī¸
â Common Questionsâ
Q: What's the difference between string and text?â
A:
- string - Short text, single line (max ~255 chars). Use for names, titles, emails.
- text - Long text, multiple paragraphs, supports formatting and HTML. Use for descriptions, articles.
Q: When should I use integer vs float?â
A:
- integer - Whole numbers only:
1, 2, 100, -5. Use for quantities, counts, ages. - float - Decimal numbers:
19.99, 4.5, -0.25. Use for prices, ratings, measurements. - real - Like float but higher precision. Use for scientific calculations.
Best practice: Plan your attribute types before adding content.
Q: What happens if I delete an attribute?â
A:
- You cant delete an attribute if it is used in an attribute set.
Q: Can I reuse the same attribute in different attribute sets?â
A: No, each attribute belongs to one attribute set. But you can:
- Create similar attributes with different markers
- Reuse entire attribute sets across multiple entities
Q: What's the "marker" and why is it important?â
A: The marker is the technical identifier you use in code:
// In your code:
product.attributeValues.product_name // â "product_name" is the marker
// VS the name (shown in admin):
"Product Name" // â This is just for humans
Rules for markers:
- Must be unique
- No spaces (use
_) - Can't start with numbers
- Use lowercase
- Choose descriptive names
Q: How do I know which type to use for my data?â
A: Ask yourself:
-
Is it text?
- Short (< 255 chars)? â
string - Long with formatting? â
text - Needs a title? â
textWithHeader
- Short (< 255 chars)? â
-
Is it a number?
- No decimals? â
integer - Has decimals? â
float - Scientific precision? â
real
- No decimals? â
-
Is it a choice?
- Pick one option? â
radioButton - Dropdown menu? â
list
- Pick one option? â
-
Is it a file?
- Picture? â
imageorgroupOfImages - Document? â
file
- Picture? â
-
Is it a date?
- Just date? â
date - Date + time? â
dateTime - Time period? â
timeInterval
- Just date? â
Q: Can I have nested attributes (attributes inside attributes)?â
A: Not directly, but you can use:
- entity type to link to other content
- json type to store structured data
- Multiple attribute sets to organize related fields
Q: How do I add validation rules?â
A: In OneEntry admin panel:
- Go to your attribute set
- Click on an attribute
- Add validators (required, min/max, regex, etc.)
- Save changes
Common validators:
- Required field
- Min/max length
- Email format
- URL format
- File size limits
- Image dimensions
đ Best Practicesâ
Do's:
- â
Use descriptive markers (
product_pricenotpp) - â Plan attribute types before adding content
- â Reuse attribute sets when possible
- â Add validators to ensure data quality
- â Document what each attribute is for
Don'ts:
- â Use spaces in markers
- â Delete attributes without checking usage
- â Change types on fields with existing data
- â Create duplicate attribute sets
- â Use generic names like
field1,text1
More information about the module's user interface https://doc.oneentry.cloud/docs/attributes/introduction
Definition of the AttributesSets moduleâ
const { AttributesSets } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
đ Related Documentationâ
- Products Module - Uses attribute sets for product data
- Pages Module - Uses attribute sets for page content
- Blocks Module - Uses attribute sets for reusable blocks
- Forms Module - Create forms with custom fields