Documentation
The content engine

Block system

A site built on Smeldr's content engine can compose its pages from blocks: typed, reusable pieces such as a hero, an image or a list of questions. A page is a set of edges in the database, so a developer or an agent can rearrange it over MCP or the command line without a code change or a redeploy, and the server renders it with one template per block type.

This page covers the data model, the block types, rendering, and the MCP tools and CLI commands that manage blocks.

What a block is

A block is a DynamicNode: the standard content lifecycle (draft, published, archived) plus two fields.

type DynamicNode struct {
    smeldr.Node                           // ID, Slug, Status, timestamps
    TypeName string `db:"type_name"`      // e.g. "hero", "faq_item"
    Fields   json.RawMessage `db:"fields"` // type-specific data as JSON
}

TypeName selects the field schema and the template. Fields carries the content. One Go type serves every block type, and all blocks live in one table, smeldr_dynamic_content, so a new block type needs no schema migration.

The block types

Sixteen block types render with a template each, templates/blocks/<type_name>.html. A seventeenth type, page, is the root a page is built on: it holds sections and has no template of its own.

Leaf blocks carry content. Required fields are marked with an asterisk:

TypeFields
content_blockTitle*, Body (Markdown), ImageID, Link
imageMediaURL, AltText, Title, Caption (Markdown), Link
heroHeadline*, Subtext (Markdown), ImageID, PrimaryLink, SecondaryLink
quoteQuoteText* (Markdown), Attribution, Context (Markdown), Link
contact_cardName*, JobTitle, Body (Markdown), Email, Phone, ImageID
faq_itemQuestion, Answer (Markdown)
link_itemTitle, URL, Target, Body (Markdown), IsCTA
html_blockAdminLabel, HTML (raw HTML, emitted as it is)
footerBody (Markdown), CopyrightText, LinkCollectionID

Collection blocks hold ordered children:

TypeTypical childrenFields
content_gridcontent_blockTitle*, Subtitle (Markdown), Layout
galleryimageTitle*, Subtitle (Markdown), Layout
faqfaq_itemTitle*, Subtitle (Markdown)
link_collectionlink_itemTitle*, Subtitle (Markdown), Layout
html_gridhtml_blockTitle*, Subtitle (Markdown), Layout
teamcontact_cardTitle*, Subtitle (Markdown), Layout
content_listthe latest items of a registered content moduleContentType*, Title, FilterTags, SortField, SortDir, Limit, SeeMoreLink

Every type also takes an optional AnchorID. list_content_type_schemas and get_content_type_schema give each field's type, format and description, once the schemas are seeded (see below).

Composition: pages are edges

A page is not a special row. It is a root block that owns other blocks through edges in smeldr_content_edges: each edge says that a parent holds a child at a position. The same table holds a page's sections and a collection's items, told apart by edge_role:

smeldr_content_edges (
    id          TEXT PRIMARY KEY,
    parent_id   TEXT NOT NULL,
    parent_type TEXT NOT NULL,
    child_id    TEXT NOT NULL,
    child_type  TEXT NOT NULL,
    sort_order  INTEGER NOT NULL,
    is_shared   INTEGER NOT NULL DEFAULT 0,
    edge_role   TEXT NOT NULL DEFAULT 'section'
)

Sections are the children of a page; items are the children of a collection block. One block can be a section of several pages: a footer can sit on every page, and an edit to it shows on all of them.

Content items as block parents

An item of any content type can host block sections, so a post can carry a hero and a gallery. Add BlockHost() to its module:

postModule := smeldr.NewModule((*Post)(nil),
    smeldr.Repo(postRepo),
    smeldr.At("/posts"),
    smeldr.BlockHost(),
)
app.Content(postModule)

app.Content registers the module as a block parent. add_section and add_item then accept a post's ID as parent_id; an ID that names no item is refused. The parent type is the Go type's name in lower case, here post.

A provider that is not a Smeldr module implements ContentParentProvider:

type ContentParentProvider interface {
    BlockParentTypeName() string
    HasBlockParent(ctx context.Context, id string) (bool, error)
}

and is registered with app.RegisterBlockParent(myProvider).

Use caseApproach
Content with its own lifecycle (a post, a story, a doc page) that also hosts block sectionsBlockHost() on its module
A composition surface with no content lifecyclea page block

Rendering with ServeBlocks

App.ServeBlocks creates the block tables if they are missing, parses every <type_name>.html in a directory into its own template, and returns a *BlockRenderer, safe for concurrent use:

renderer, err := app.ServeBlocks("templates/blocks")
if err != nil {
    log.Fatal(err)
}

// In a handler: render the page with this ID.
html, err := renderer.Render(ctx, "page", pageID)
if err != nil {
    // a database fault; rendering failures are logged, not returned
    http.Error(w, "page unavailable", 500)
    return
}

Render returns the HTML of the page's published sections, in order, each collection with its items. A block that is not published, missing, malformed, or has no template is skipped and logged: it never fails the page.

What a template receives

Each template gets a map with:

KeyValue
.ID, .Slug, .Statusthe block's own
.AnchorIDthe block's AnchorID field, empty when it has none
every key of Fieldsat the top level: .Title, .Body and so on
.Itemsfor a collection: its items, each already rendered by its own template

Markdown fields arrive as safe HTML, raw HTML fields as they were stored, and plain strings are escaped by html/template.

Keys are PascalCase. Templates read .Title and .Body, so a block's fields must be stored as Title and Body. For a type with a seeded schema, a field in another case is refused as unknown. A type with no schema stores it, and the template renders it blank.

Reference fields

A field named ImageID on a content_block, hero or contact_card holds another block's ID. Render resolves it into .Image, with the referenced image's data:

<!-- templates/blocks/hero.html -->
<section class="hero">
  <h1>{{ .Headline }}</h1>
  <p>{{ .Subtext }}</p>
  {{ with .Image }}
    <img src="{{ .MediaURL }}" alt="{{ .AltText }}">
  {{ end }}
</section>

An image that is not published, or an ID that names no block, renders nothing in {{ with .Image }}, and no error. .Image carries plain data: references in it are not followed further.

Collection templates

A collection template wraps its rendered items:

<!-- templates/blocks/gallery.html -->
<div class="gallery" data-layout="{{ .Layout }}">
  {{ range .Items }}{{ . }}{{ end }}
</div>

Managing blocks with MCP

The block tools come with mcp.WithBlocks():

mcpSrv := mcp.New(app, mcp.WithBlocks())
mcpSrv.Register(app)

The server binary turns them on with ENABLE_BLOCKS.

Blocks (Author role)

Blocks are addressed by ID. They have no slug and are not browsable resources.

ToolWhat it does
create_nodecreate a draft block from type_name and fields; returns its id
update_nodemerge fields into a block; keys left out keep their values
get_noderead a block at any status
list_nodeslist blocks, optionally by type_name and status
publish_nodepublish a block; publishing it again changes nothing
archive_nodearchive a block
// create_node
{ "type_name": "hero", "fields": { "Headline": "Welcome", "Subtext": "Built for agents" } }
// publish_node
{ "id": "<the id create_node returned>" }

Composition (Editor role)

Pass only IDs: the tools read the parent's and child's types from the stored blocks.

ToolWhat it does
add_sectionappend child_id as a section of parent_id
reorder_sectionsset the order of parent_id's sections, from ordered_child_ids
remove_sectionremove child_id from parent_id's sections
add_itemappend child_id as an item of a collection
reorder_itemsset the order of a collection's items
remove_itemremove an item from a collection

To build a page: create a page block, create and publish a hero, then add_section with the page as parent_id and the hero as child_id.

Typed block tools and validation

A program that seeds the block schemas gets one typed tool per block type, and validation of fields. Seed them where the block tables are made:

func migrateDB(db *sql.DB) error {
    if err := smeldr.CreateBlockTables(db); err != nil {
        return err
    }
    if err := smeldr.CreateSchemaTable(db); err != nil {
        return err
    }
    return smeldr.SeedBlockTypeSchemas(db)
}

SeedBlockTypeSchemas adds the sixteen schemas and never overwrites a schema that is there, so it is safe on every start. The server binary does not seed them: with it, create_node is the way to create a block, and its fields are not checked.

With the schemas seeded, the MCP server offers these tools, each with the type's fields as named parameters:

create_content_block    create_image           create_hero
create_quote            create_contact_card    create_faq_item
create_link_item        create_html_block      create_footer
create_content_grid     create_gallery         create_faq
create_link_collection  create_html_grid       create_team
create_content_list

A typed tool takes the fields at the top level; create_node nests them under fields:

// create_hero
{ "Headline": "Welcome", "Subtext": "Built for agents" }
// create_node
{ "type_name": "hero", "fields": { "Headline": "Welcome" } }

get_content_type_schema gives one type's fields:

// get_content_type_schema { "type_name": "hero" }
{"fields":[
  {"name":"Headline","type":"string","required":true},
  {"name":"Subtext","type":"string","required":false,"format":"markdown"},
  {"name":"ImageID","type":"string","required":false,"description":"ID of an Image block"},
  {"name":"PrimaryLink","type":"object","required":false,"description":"Primary CTA link sub-object"},
  {"name":"SecondaryLink","type":"object","required":false,"description":"Secondary link sub-object"},
  {"name":"AnchorID","type":"string","required":false}],
 "label":"Hero","type_name":"hero"}

list_content_type_schemas lists every type with its label. When a type has a schema, create_node and update_node check fields against it:

  • a field the schema does not have is refused, for example unknown field "Nope" for type "hero";
  • a missing required field is refused, for example required field "Headline" missing for type "hero";
  • a type with no schema is stored as it is.

Managing blocks with the CLI

smeldr-cli block makes the same calls from a shell.

# Blocks (Author role)
smeldr-cli block node create --type hero --field Headline="Welcome" --field Subtext="Hello"
smeldr-cli block node create --type content_block --fields '{"Title":"Post","Body":"..."}'
smeldr-cli block node list
smeldr-cli block node list --type hero --status published
smeldr-cli block node list --json
smeldr-cli block node get <id>
smeldr-cli block node publish <id>
smeldr-cli block node archive <id>
smeldr-cli block node update <id> --field Headline="New headline"

# Composition (Editor role)
smeldr-cli block section add <page_id> <block_id>
smeldr-cli block section reorder <page_id> <id1,id2,id3>
smeldr-cli block section remove <page_id> <block_id>
smeldr-cli block item add <collection_id> <item_id>
smeldr-cli block item reorder <collection_id> <id1,id2,id3>
smeldr-cli block item remove <collection_id> <item_id>

--field keeps the key as you type it, so write --field Headline=..., not headline.

Behaviour

PropertyBehaviour
Only published blocks renderdraft and archived blocks are skipped
Gracefula missing block, a missing template or malformed fields: skipped and logged, never a page error
Batched loadingthe tree loads a level at a time, in batched queries, not one query per block
Cycle-safea depth limit of 16 stops a shared block that contains its own ancestor
Shared blocksa block in several pages shows an edit on all of them