Expand description
Built-in blocks shipped with rcms. Each one is a single Rust
struct plus a Tera template at blocks/<type_name>.html (in
crate::admin::register_templates). Host crates register
additional blocks via crate::register_block!.
These ship with sensible defaults and a minimal HTML template so the editor + render path produce a working page on day one. Hosts can override the template by registering a same-named template before the bundled load — Tera resolves the most-recently-added template, which is the standard precedence rule.
Structs§
- Boolean
Block boolean— Single checkbox; the template renders nothing by default (host overrides decide what “true” means in context — show a banner, flip a class, …).- Choice
Block choice— Editor picks one entry from a host-supplied list of(value, label)pairs. Hosts overrideBlock::fieldsby subclassing to set their own option list (the registered default lands as an empty select — actionable only when a host extends).- Code
Block code— a fenced code block with a language hint. Renders the standard<pre><code class="language-…">markup that client highlighters (Prism / highlight.js / Shiki) pick up automatically. The body is HTML-escaped by Tera, so it displays verbatim and can’t inject markup. Server-side highlighting (syntect) would add a heavy dependency and is better as an opt-in follow-up — this markup is highlighter-agnostic.- Date
Block date— ISO-8601 date string (YYYY-MM-DD).- Date
Time Block datetime— ISO-8601 datetime string.- Decimal
Block decimal— Like FloatBlock but the default ships with a stablestep="any"hint via the Float widget. Hosts that need bounded precision pass a customBlockFieldMetavia thewith_metasetter (chained at registration time on a subclassed variant). Storage is the decimal as a string so banking-grade precision round-trips through serde without f64 loss.- Document
Chooser Block document_chooser— Picks a non-imagecms_mediarow (e.g. PDF, archive) via the modalDocumentChooserwidget. Stored value is the media id as a stringified integer.- Email
Block email— Browser-validates the shape via<input type="email">; the template renders amailto:link.- Embed
Block embed— A single URL; the public template renders a responsive embed.Self::extra_contextruns the URL throughcrate::embed::resolveso a YouTube watch or Vimeo page URL becomes the provider’s embeddablesrcwith the right aspect ratio; unrecognised URLs link out rather than iframing an arbitrary site.- Float
Block float— Free-form floating-point input. Distinct fromIntegerBlock(which usesWidgetKind::Numberwithstep="1") — this one accepts decimals.- Heading
Block heading— a heading with a level choice. Two fields:text(the heading body) andlevel(2..4, defaulting to H2). Template emits<h{level}>{text}</h{level}>.- Image
Block image— Picks acms_mediarow- Integer
Block integer— Numeric input; the template renders the value as-is. Editors needing a unit / formatting override the template.- Multiple
Choice Block multiple_choice— Distinct fromChoiceBlock(single-pick<select>) — this one renders stacked checkboxes and stores a JSON-array string. Hosts register a subclassed variant with their own option list (default ships with no options, likeChoiceBlock).- Page
Chooser Block page_chooser— Picks a singlecms_pagerow via the modalPageChooserwidget; stores the page id as a stringified integer.- Paragraph
Block paragraph— One markdown field rendered through the rcms safe-markdown pipeline on the public side.- Quote
Block quote— Textarea body + optional attribution.- RawHtml
Block raw_html— Editor types HTML; the public template sanitises through the same ammonia pipeline as the Markdown widget (crate::markdown::render’s post-pass) so<script>/<iframe>/on*handlers are stripped.- Regex
Block regex— Text input with a pattern validator. The default ships pattern-less (accepts anything); hosts subclass + overridefields()to attach a regex viaBlockFieldMeta::default().pattern("^[A-Z]+$"). The browser validates on submit via HTML5pattern.- Rich
Text Block rich_text— Editor surface for hosts wiring a WYSIWYG (EasyMDE / TipTap / Draftail) via theWidgetKind::RichTextwidget’sdata-widget-mode="richtext"hook. Without a host enhancer the textarea ships with the existing markdown toolbar — same editor as ParagraphBlock but stores HTML directly.- Snippet
Chooser Block snippet_chooser— Picks acms_snippetrow via the modalSnippetChooserwidget. The stored value is the snippet id as a stringified integer.- Static
Block static— Marker block with no fields; the public template emits whatever static HTML the host wants (divider, call-out, branded heading rule). Inserting one in a StreamField is the editor’s signal “render the host’s static content here”.- Table
Block table— Editor enters TSV (one row per line, tab-separated cells); the public template renders a<table>with the first row as<thead>. Cells preserve as plain text. Pasting straight from a spreadsheet works because Excel / Google Sheets / Numbers all serialise selected ranges as TSV on the clipboard.- Text
Block text— Multi-line plain text rendered inside<p>with newlines preserved.- Time
Block time— ISOHH:MM[:SS]string.- Typed
Table Block typed_table— Schema-driven typed grid where each row’s cells are individually-typed widgets (unlikeTableBlockwhich is TSV-only).- Typed
Table RowBlock typed_table_row— one row inside the default TypedTableBlock. Three columns:label(text),value(number),notes(text). This serves as a working baseline; hosts that need a different column schema register their own row block + their ownTypedTable-style wrapper.- UrlBlock
url— Browser-validates via<input type="url">; the template renders an anchor.
Functions§
- safe_
href - An author-typed link target, or
Nonewhen it would run script.