Skip to main content

Block

Derive Macro Block 

Source
#[derive(Block)]
{
    // Attributes available to this derive:
    #[block]
    #[field]
}
Expand description

#[derive(Block)] — declarative block definition. Walks #[block(...)] + #[field(widget = …)] attrs to emit the Block trait impl + register_block! inventory submission in one go. Coexists with the Block trait through Rust’s separate macro / type namespaces (same pattern as #[derive(PageType)] alongside PageType). #[derive(Block)] — generates the rustango_cms::Block trait impl from #[block(...)] and #[field(...)] attributes plus a global inventory registration so the block joins the registry at link time.

Author surface:

ⓘ
use rustango_cms::Block;

#[derive(Default, Block)]
#[block(icon = "title", group = "Headings", description = "Section heading.")]
pub struct Heading {
    #[field(widget = Text, required)]
    pub text: String,
    #[field(widget = Select, label = "Level", options(h2 = "H2", h3 = "H3"))]
    pub level: String,
}

type_name defaults to the snake_case of the struct name; verbose_name defaults to the struct name as written. Override either via #[block(type_name = "…")] / #[block(verbose_name = "…")].