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:
| Type | Fields |
|---|---|
content_block | Title*, Body (Markdown), ImageID, Link |
image | MediaURL, AltText, Title, Caption (Markdown), Link |
hero | Headline*, Subtext (Markdown), ImageID, PrimaryLink, SecondaryLink |
quote | QuoteText* (Markdown), Attribution, Context (Markdown), Link |
contact_card | Name*, JobTitle, Body (Markdown), Email, Phone, ImageID |
faq_item | Question, Answer (Markdown) |
link_item | Title, URL, Target, Body (Markdown), IsCTA |
html_block | AdminLabel, HTML (raw HTML, emitted as it is) |
footer | Body (Markdown), CopyrightText, LinkCollectionID |
Collection blocks hold ordered children:
| Type | Typical children | Fields |
|---|---|---|
content_grid | content_block | Title*, Subtitle (Markdown), Layout |
gallery | image | Title*, Subtitle (Markdown), Layout |
faq | faq_item | Title*, Subtitle (Markdown) |
link_collection | link_item | Title*, Subtitle (Markdown), Layout |
html_grid | html_block | Title*, Subtitle (Markdown), Layout |
team | contact_card | Title*, Subtitle (Markdown), Layout |
content_list | the latest items of a registered content module | ContentType*, 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 case | Approach |
|---|---|
| Content with its own lifecycle (a post, a story, a doc page) that also hosts block sections | BlockHost() on its module |
| A composition surface with no content lifecycle | a 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:
| Key | Value |
|---|---|
.ID, .Slug, .Status | the block's own |
.AnchorID | the block's AnchorID field, empty when it has none |
every key of Fields | at the top level: .Title, .Body and so on |
.Items | for 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.
| Tool | What it does |
|---|---|
create_node | create a draft block from type_name and fields; returns its id |
update_node | merge fields into a block; keys left out keep their values |
get_node | read a block at any status |
list_nodes | list blocks, optionally by type_name and status |
publish_node | publish a block; publishing it again changes nothing |
archive_node | archive 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.
| Tool | What it does |
|---|---|
add_section | append child_id as a section of parent_id |
reorder_sections | set the order of parent_id's sections, from ordered_child_ids |
remove_section | remove child_id from parent_id's sections |
add_item | append child_id as an item of a collection |
reorder_items | set the order of a collection's items |
remove_item | remove 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
| Property | Behaviour |
|---|---|
| Only published blocks render | draft and archived blocks are skipped |
| Graceful | a missing block, a missing template or malformed fields: skipped and logged, never a page error |
| Batched loading | the tree loads a level at a time, in batched queries, not one query per block |
| Cycle-safe | a depth limit of 16 stops a shared block that contains its own ancestor |
| Shared blocks | a block in several pages shows an edit on all of them |