Create A Block#
Blocks live in resources/views/blocks:
<section> <h2>Hello block</h2></section>This creates a block named Notice in the editor.
Add Fields#
Use front matter when the block needs editor controls:
title: Herocategory: Sectionsfields: heading: text intro: textarea---<section> <h2>{{ heading }}</h2> <p>{{ intro }}</p></section>The part above --- describes the block. The part below --- is the rendered markup.
Front Matter Fields#
Use these fields above the --- separator:
| Field | Purpose |
|---|---|
title | The block label shown in the editor. |
name | Alternative label source when title is not set. |
description | Short description for the block inserter. |
icon | Dashicon name for the block. |
category | Inserter category. TemplateX saves it as kebab-case. |
fields | Editor fields for editable values. See Block Fields. |
variants | Editor options that can change markup or classes. See Block Variants. |
show | Limits where the block appears in the editor. See Block Show Rules. |
auto_editable | Lets TemplateX infer editable content from simple HTML. See Auto Editable Blocks. |
Read Field Values#
Block fields work like other TemplateX values:
<h2>{{ heading }}</h2><p>{{ intro }}</p>TemplateX escapes field values for where they appear, then compiles the block to native WordPress PHP.
Keep Blocks Small#
A good block owns one editable piece of the page. Use partials when a block shares markup with templates or other blocks:
title: Featured Postcategory: Sectionsfields: eyebrow: text---<section> <p>{{ eyebrow }}</p> <PostCard /></section>