Attribute definition
Attributes are specified in an object where each key is the attribute name:Attribute schema
Each attribute definition must include eithertype or enum, and may include additional fields.
Type validation
Thetype field indicates the data type. Must be one of:
nullbooleanobjectarraystringintegernumber(same asinteger)
Enum validation
Restricts values to a fixed set:Value sources
Thesource field determines where attribute data is stored.
No source (comment delimiter)
Without asource, data is stored in the block’s comment delimiter:
attribute source
Extracts values from HTML element attributes:Boolean attributes
For existence checks likedisabled:
text source
Extracts inner text usingtextContent:
html source
Extracts inner HTML usinginnerHTML:
query source
Extracts arrays of objects from multiple elements:meta source (deprecated)
Extracts values from post meta:Selectors
Theselector field uses CSS selector syntax:
Default values
Provide fallback values with thedefault field:
Attribute roles
Therole property provides semantic meaning:
content role
Marks user-editable content:local role
Marks temporary, non-persistent data:Using attributes
In the edit function
In the save function
Attributes with asource must be saved correctly:
source are saved automatically in the comment delimiter.
Complete example
Best practices
- Store as much data as possible in HTML rather than comment delimiters
- Use appropriate
typevalues for validation - Provide
defaultvalues for optional attributes - Use
role: 'content'for user-editable content - Use descriptive attribute names
- Consider deprecations when changing attributes