Open a site that has been alive for two years and look for repetition. The same header pasted into forty pages. A card that was copied for the blog, copied again for the team page, and has since drifted into three slightly different cards. A list of recent posts that someone typed by hand last year and nobody has touched since. None of this is a design failure. It is a structure failure: the site never decided which pieces repeat, so every page repeated them on its own.
Etch gives you three tools for this, and this tutorial is about those three. Components are reusable pieces of structure, such as a header or a card, that pages reference instead of copy. Loops repeat a piece of markup over a set of data, such as posts, terms, users or a typed list. Dynamic data is the text in curly braces that fills the markup from that data when the page renders. A fourth, smaller tool, scripts on elements, lets a piece of behaviour travel with the markup that needs it.
The single most important idea is that scope is strict and visible. A loop item exists only inside its loop. A component sees only the site-wide data and the values passed into it. A key resolves where you write it, not where you meant it. Nearly every beginner bug in all three areas is a scope bug: a card that renders blank, a loop that repeats the wrong thing, a custom field that comes back empty. Learn where each key can be read and most of the debugging disappears.
A word on where this comes from. wpresident.com was built in November 2026 by an AI agent (Claude Code) that drove WordPress 7.1 through NibWP, a plugin that exposes a site’s abilities over MCP, the Model Context Protocol. The site runs Etch 1.8.3. We worked through that API, not through Etch’s visual canvas, and we never used the canvas. So this tutorial can tell you how Etch stored our components, loop presets and scripts, what the markup looked like and what went wrong. It cannot tell you how any of it feels to drag around on screen. NibWP is made by the same publisher as this website. It was the route we took, not something you need, and everything here holds if you build in the canvas or in your own scripts.
Two kinds of statement appear in the tutorial, and you should be able to tell them apart. Sentences that say we used, we built or we hit are first-hand and come from that build. Sentences that say what the documentation shows come from Etch’s public documentation, which we read in November 2026. We did not exercise those features on the site, so check them against the current pages before you rely on them, because Etch moves quickly.
The order is the order we would work in: how Etch stores things, then components, then loops, then dynamic data and custom fields, and finally escaping, scripts and a list of failures with the first thing to check for each.
Key points
- Know where each Etch piece is stored, because that sets the reach of an edit: a page change touches one page, while a component or loop preset change touches every place that uses it.
- A component sees only site-wide data and the values passed to it, so loop keys such as item.title must be mapped into props on the instance and never typed inside the component.
- Loop presets with parameters and defaults, written like $limit ?? 6, let a few named queries serve every page, and each call site passes only what differs.
- Use modifiers for presentation and the etch/dynamic_data/post filter for shaping data: return an array, register the callback with two accepted arguments, and return raw values because Etch escapes text itself.
- Scripts attached to elements printed as deferred module scripts in the head for us, so write them to find their elements after parsing and to do nothing when those elements are absent.
- Etch registers styles while blocks render and prints them late in wp_head, so in a custom canvas render the content first or the page styles go missing.
- We worked through the API and never used the visual canvas, so treat anything beyond our listed experience as documentation-level and verify it on a staging copy.
How Etch stores a page, so you know what you are editing
Before the first component, look at what Etch actually writes into WordPress. Because we worked through the API, we handled this data directly, and it is a good way to learn the system: nothing is hidden behind a panel.
Page content is stored as blocks in post_content. The block names we met were etch/element for an HTML element, etch/text for text, etch/component for a reference to a component, etch/loop for a loop and etch/condition for a conditional. They are ordinary WordPress blocks, so a page is a tree of them, and what you author is what the browser receives: the markup we saw had no wrapper divs that we had not written ourselves.
Classes are kept apart from the page. Each class carries its CSS as its own style entity, and CSS nesting worked, so a hover rule or a media query sits inside the class it changes. There is also one global stylesheet, stored in an option. Components are wp_block posts, and a page includes one through an etch/component block. Loop presets live in an option called etch_loops. A script is not a separate file: it is an attribute on the element that needs it.
That list matters for one reason, which is reach: know it before you edit. Editing a page changes one page. Editing a component changes every page that references it. Editing a preset changes every loop that calls it. Editing a class changes every element that uses it, and editing the global stylesheet changes the whole site. The figure sets them side by side.
Two habits follow. First, fix a problem in the piece whose reach matches the problem. If one card looks wrong on one page, look at that page or that instance. If every card is wrong, look at the card component or its class. Second, treat shared pieces with more care than pages. A typo in a page is a typo. A typo in the header component is on every URL at once.
The data model also tells you what to back up and what to move between sites. Pages and component posts are posts, so a database backup or a full staging copy brings them along. Loop presets and the global stylesheet are options, and WordPress’s built-in content export covers posts but not options, so a content-only export can carry your pages without your presets. When this tutorial says to verify on staging, this is the first thing to verify: that components and presets arrived, not only pages.
Where each piece lives and who feels an edit
| Where it lives | Who feels an edit | |
|---|---|---|
| Page content | Blocks in post_content | That one page |
| Component | A wp_block post, referenced by etch/component | Every page that references it |
| Loop preset | An entry in the etch_loops option | Every loop that calls the preset |
| Class | A style entity that carries its own CSS | Every element that uses the class |
| Global stylesheet | One option | The whole site |
| Script | An attribute on one element | Every page that renders that element |
Components: one source, many pages
The documentation describes a component as a reusable, self-contained piece of a site that handles one part of its look or behaviour: a header, a footer, a card, a call to action, a button. You build it once and use it across many pages. The sentence that carries the weight is the one about editing: when you update a component, all instances reflect the change.
In our build this was the first thing that mattered. The header and the footer were components, stored as wp_block posts and referenced from every page through an etch/component block. About 45 pages shared one header and one footer, and none of those pages held a copy of the markup. Changing the footer meant editing one post.
It helps to say what a component is not. It is not a template: the documentation keeps a Templates section for layouts of a kind of content, such as every single post, apart from components, which pages and templates can both include. It is not a class either. A class makes things look alike, while a component makes things be the same thing. And it is not a pasted snippet. A pasted snippet drifts, and a referenced component cannot.
That last property is also the risk. A component is a contract, and everything that includes it inherits any change, good or bad. Three rules decide what deserves to become one.
- Make it a component when it is page chrome that must be identical everywhere, such as the header and the footer.
- Make it a component when the same structure appears in three or more places with different content, such as a card.
- Leave it as plain elements with shared classes when only the look repeats and the contents differ, such as section wrappers, because forcing those into a component produces one with twenty options.
The documentation also lists native, pre-made components separately. This tutorial covers the ones you author, because that is what we built.
Finally, wp_block is the post type WordPress also uses for reusable blocks, so component posts are ordinary posts with ordinary behaviour. They can be listed, backed up and copied to staging like other content. Before you delete one, find out on a staging copy which pages still reference it. We did not test what a page does when its component is gone, so do not assume it fails gracefully.

Props, slots and scope: varying a component without forking it
A component that can only ever show one thing is a copy with extra steps. Props are what turn it into a tool. The documentation describes them as the customisable properties of a component and splits them into two groups. Data props hold content that changes between instances, such as a name, a price or an image. Behaviour props change how an instance looks or acts, such as a toggle or a layout option.
The documented prop types are Text, Boolean, Select, Media, Loop, Object, Class and Group. Every prop has a label, which is what you read in the editor, and a key, which is what the code uses. You map each prop to an element inside the component, then fill the prop on every instance. Inside the component the documentation reads props through a props stem, in examples such as props.productCategory and props.rating.
Slots are the other half. A slot is a drop zone defined inside a component, and each instance can fill it with its own content without touching the component. The documentation writes a slot as {@slot name} inside the component and a filled slot as {#slot name}{/slot}. A slots.name.empty check is true when nothing was put in, which lets a component hide a wrapper, as in {#if !slots.footer.empty}, so an unused slot leaves no empty box behind.
Think of all this as a function. Props are the arguments. Slots are the body you hand in. A class prop is a styling hook. And like a function, the component has its own scope. The documentation puts it bluntly: never use loop or template keys directly inside a component. A component can read global data, meaning this, site and url, plus whatever arrives through its props, and nothing else. So {item.title} typed inside a card component does not resolve. The key has to be supplied as a prop value on the instance, which is the subject of the card-in-a-loop section.
Everything in this section is documentation-level. Our first-hand component work was the shared header and footer, described next.
A few rules keep components usable. Keep the number of props small, because a component with a dozen of them is a template in disguise and is harder to use than the markup it replaced. Prefer a boolean prop with a condition to a second component, as in the documentation’s example of an on-sale prop that shows a badge. Use a slot for a block of content that genuinely varies, and do not use one where a prop will do: slot content cannot read a loop’s item from inside the component, a limit the documentation states, and it points to an Object prop for passing per-item data.
How should this component vary?
Build the shared header and footer, then prove they are shared
Build the header and the footer before any page. Every page will include them, every later page is judged against them, and they are the cheapest test of whether your whole pipeline works: classes, tokens, scripts and cache.
Our route was an HTML-to-component converter exposed through NibWP. We sent it a payload of Etch blocks plus styles and set its dry-run flag first. A dry run validates without writing, and the response lists passed and failed checks, warnings and suggestions. That is where the strict rules showed up. Class names had to be BEM-like with a brand prefix. Colours had to be tokens with a fallback, so a hard-coded hex was flagged, and an rgba() value inside a var() fallback failed. Font sizes had to use a token style, and complex clamp() or min() fallbacks were rejected. Every element needed a class, with SVG primitives exempt. We fixed what a dry run flagged before pushing for real. The push used a preflight token tied to the target post and to a push mode, which was replace_section for us. Those rules belong to the converter, not to Etch, but they make a good checklist for any builder.
The order we would follow, with or without a converter:
- Write the component as plain semantic HTML first: a header element and a footer, each with a labelled navigation, every element carrying a prefixed class.
- Put every colour and size behind a token with a fallback, so the component still renders if the framework stylesheet is missing.
- Dry-run, fix what fails, then push.
- Reference the component from one page, then from one page of each other type.
- Read the page source, not just the screen. Confirm the header markup appears once and that the page’s styles printed.
- Purge the page cache if one sits in front of the site, then confirm you are looking at the new version and not a stored one.
Expect friction in the tooling. The validator’s suggestions were numerous, 89 on one page, and we found no way to silence them, so read the pass and fail list first and treat the suggestions as hints. A full page push took roughly 10 to 30 seconds, and when the host struggled the calls timed out. One run returned a database connection error, a host problem, but it shaped the workflow: we added retries, and after a timeout the safe move is to check whether the write landed before you send it again.
Finally, keep volatile content out of shared components. A banner or a campaign link that changes every month belongs in data the component reads, not in markup someone must republish.
Loops: four sources and one syntax
A loop repeats whatever you put inside it, once for every item in a set of data. The documentation lists four sources for that data: WP Query for posts and custom post types, WP Terms for taxonomy terms, WP Users for users, and JSON for a static or dynamic array. Its developer reference also names a main-query type, which suits templates, where the documentation says the main query often drives the loop. On a regular page, by contrast, a WP Query loop needs a query of its own.
In our build a loop was stored as an etch/loop block, and the text form below is the way the documentation writes it. The loop opens with a source name and a name for the current item, and everything between the tags repeats.
<ul class="acme-list">
{#loop latestPosts as post, index}
<li class="acme-list__item" data-position="{index}">
<article class="acme-card">
<h3 class="acme-card__title">{post.title}</h3>
<a class="acme-card__link" href="{post.permalink.relative}" aria-label="Read {post.title}">Read more</a>
</article>
</li>
{/loop}
</ul>
Four details in that sample matter. The item name is yours to choose, so pick one that reads well, such as post, author or term. A second name after a comma gives a zero-based index, which the documentation uses in a data attribute and for treating the first item differently. Keys work in attributes as well as in text, and static and dynamic text can be mixed, as in the aria-label. And the loop wraps the li, not the article, so the list stays valid HTML: a ul should contain li elements, and a loop around the article alone would put articles directly inside the list.
The documentation also shows an inline loop over a literal array, such as {#loop [1,2,3,4,5] as item}, for a fixed number of repeats, which suits things like five rating stars.
Choose the source by asking what you are repeating, as the figure does. Two cautions apply. A loop over users prints whatever you place in it, so output a name and a link and never an email address. A JSON loop suits small typed lists such as tab labels, but a long array pasted into a block is content editors cannot find. If the list will grow, make it posts or terms.
A loop with no results renders nothing by default, which is fine for a related-posts strip and a bug for a grid under a heading.
Which loop source fits the data?
Loop presets, parameters and defaults
Here is where loops become a system instead of a feature. In our build, loops used presets stored in an option called etch_loops. A named preset holds the query arguments, and it accepts parameters with defaults, written like $limit ?? 6: use the value the call site passes, or fall back to six. The documentation calls these saved loops and loop arguments, and compares them to CSS custom properties: a placeholder in the definition, a value supplied where the loop is used.
That changes how you plan. Instead of a different query on every page, you define a handful of presets and each page supplies only what differs. Here is an illustrative example, not a record of our site. A publication has six department pages and a post template. It needs a latest-posts preset with a limit, a department preset with a department and a limit, and a related-posts preset that excludes the current post. The call sites look like this, in the documentation’s syntax:
{#loop latestPosts as item}
{#loop latestPosts($limit: 3) as item}
{#loop departmentPosts($department: "ai", $limit: 8) as item}
{#loop relatedPosts($post_id: this.id) as post}
The first call uses every default. The second overrides one value. The third passes a quoted string, which the documentation requires when the value is text. The fourth passes dynamic data, this.id, the current post’s ID. Inside a component, a prop can be the value, as in $count: props.numberOfPosts, which lets the parent decide how many items to show.
The arguments follow WordPress query parameters. The documentation writes them in PHP array style, with the placeholder where a value would go. The sketch shows the shape, not code for a theme, and the developer reference writes the same thing as a keyed object, so check the current form.
array(
'post_type' => 'post',
'posts_per_page' => $limit ?? 6,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
)
Four rules from the documentation prevent most trouble. If the same placeholder appears twice with different defaults, the first default wins everywhere, so use two names such as $count and $offset. Values that WordPress expects as an array must be written as one, so excluding the current post means wrapping the placeholder in brackets. Text values are passed in quotes. And the default -1, which means all posts, is a trap on a large site: pick a real number.
Name each preset for its purpose, not its page, and after you change a parameter count the items that come out, because a misspelt parameter name is likely to leave the default in force, and a grid of six looks as plausible as a grid of three.
How a call becomes a list of items
- Call site names a presetThe loop block says which preset to use and passes only the values that differ.
- Parameters match by nameEach passed value is paired with the placeholder of the same name in the preset.
- Defaults fill the gapsA placeholder written with a double question mark falls back to its default when the call omits it.
- Arguments reach the queryThe finished arguments go to the data source, for example a WordPress query.
- The loop body repeatsOnce for each returned item, with the item keys readable only inside the body.
Card components inside loops: crossing the scope boundary
The card is the classic place where all three ideas meet, and where the scope rule bites. The loop owns the item. The component owns its markup. The instance, the spot on the page where you drop the component into the loop, is the only place where both are visible, so that is where you connect them.
The documentation’s workflow has three steps. Build the card with props: a Text prop for the title, a Media prop or a Text prop for the image, and a Text prop for the link. Place an instance of the card inside the loop. Then fill each prop on the instance with a key from the item:
- The title prop gets
{item.title}. - The image prop gets
{item.image.id}. - The link prop gets
{item.permalink.relative}.
The card then receives plain values. It does not know they came from a loop, which is why one card can serve a home page strip, an archive and a related-posts block, and why you can also fill it by hand on a landing page. A template works the same way: a heading prop gets {this.title}.
This is also where bugs live, so debug in a fixed order. A card that renders with blank fields almost always means one of three things: a prop on the instance was left empty, its key was misspelt, or someone typed an item key inside the component, where it cannot resolve. Check the instance first. Because the card is isolated, you can fill it with static values on a scratch page. If it renders correctly there, the fault is in the mapping, not in the card.
The documentation shows nested loops for hierarchical data, such as categories with their posts. The outer loop is {#loop categories as category} and the inner one passes the category into a parameter, as in {#loop posts($cat: category.id) as post}. Give every loop a distinct name. If both loops use the same name, the inner one hides the outer one completely, and a field such as {item.name} comes back empty.
The documentation’s workaround is a second loop that runs only when the data has zero length, written with posts.length().equal(0, [1], []), and the page says a more official method is planned. We did not use it, so check the current page. The plain alternative is to design the page so an empty list is acceptable.
Last, a page cache keeps showing the old list until it is purged. On the ad manager we used ACF’s acf/save_post hook to purge the page cache when its data changed, and the same idea applies to any list that must update promptly.
Passing a loop item into a card
- Loop supplies an itemEach pass makes one item available under the name you chose, inside the loop only.
- List wrapper repeatsThe li sits inside the loop, so the list markup stays valid.
- Instance maps the propsEach prop on the instance is filled with an item key such as the title or the link.
- Component receives plain valuesInside the card only props and site-wide data can be read.
- Card markup rendersOne card per item, identical in structure and filled with that item data.
Dynamic data: stems, keys and modifiers
Dynamic data is text in curly braces that Etch resolves when the page renders. It can fill text and attributes, and the documentation shows it inside aria attributes to make the point. A key has two parts: a stem that says where to look, and a path that says what to read.
The stems you will meet are few. this is the current post or the template’s data. item, or whatever name you gave the loop item, is the current loop item. props holds a component’s own values. site and url are global, and user and options appear in the documentation’s filters for user data and option data. In our build, {item.title} and {item.meta.key} worked inside loops, where key is the name of a meta field. The documentation adds keys such as {item.excerpt}, {item.permalink.relative} and {item.featuredImage.url}, with the image’s alt text under {item.featuredImage.alt}.
Modifiers are methods on the end of a path, as in item.value.modifier(), and stacked modifiers run in the order you write them. The documented families cover most presentation needs:
- Strings: truncateWords, truncateChars, stripTags, toLowerCase, toSlug, replace and replaceAll.
- Numbers: numberFormat and round.
- Dates: dateFormat, which takes PHP date codes and returns invalid input unchanged.
- Arrays: at, length, join and pluck, which pulls one property out of each object in a list.
Two examples show the pattern. {item.excerpt.stripTags().truncateWords(20)} removes markup and then cuts to twenty words. {item.meta.event_date.dateFormat("j F Y")} formats a date stored in a meta field, where the field name is an illustration. Order matters: strip tags before you truncate, or the cut can land inside markup.
The decision rule is where to stop. A modifier chain is presentation, and it belongs in the template. Once you chain more than two or three, combine two fields, or need a fallback when a value is missing, you are writing logic in a place that cannot be tested or reused. Move that work into PHP and expose a finished value, which the next section covers.
One honest gap: we did not check what each key prints when its value is missing. Before you publish a loop, test it with a post that lacks the field and look at the source.
Adding custom fields with the dynamic data filter
Etch cannot know about the fields your site invented, so it offers a filter. In our build we added custom fields to loop items with the etch/dynamic_data/post filter, and they appeared as keys on the item. The documentation describes the filter as extending the {this.CUSTOM} key. Your callback receives the array of dynamic data for the post and the post ID, adds its own entries and returns the array.
Here is a generic version of the pattern. The key name acme and the meta keys are examples, so replace them with your own.
add_filter('etch/dynamic_data/post', function ($data, $post_id) {
$categories = get_the_category($post_id);
$data['acme'] = array(
'kicker' => (string) get_post_meta($post_id, 'acme_kicker', true),
'read_minutes' => (int) get_post_meta($post_id, 'acme_read_minutes', true),
'department' => $categories ? $categories[0]->name : '',
);
return $data;
}, 10, 2);
After that, a template reads {this.acme.kicker}, and a loop reads {item.acme.kicker}. Four details decide whether it works.
- Return an array. The documentation says that if you return anything else, Etch ignores the filter and keeps the previous data.
- Pass
10, 2at the end. WordPress hands a callback only the arguments you declare, so without the 2 a two-parameter callback fails. The hooks documentation shows these numbers, and the sibling filters for user, term and option data follow the same pattern with their own argument counts. - Return raw values. Etch escapes text itself, so do not run esc_html over the strings, or they will arrive double-encoded.
- Keep the callback cheap. We have not traced how often Etch calls it, so assume once per item and run no new queries inside it. Meta and category data are normally already loaded with the posts.
Put the code in a small plugin, or a snippet plugin, rather than the theme, so a theme change does not silently delete your keys. And check the syntax before you save. A PHP error is not a cosmetic failure: in our sandbox, a stray apostrophe inside one PHP string triggered a crash safe mode that disabled every sandbox plugin, and the custom front-end canvas disappeared until we fixed the file and deleted the marker. A one-line check catches that class of mistake.
$ php -l acme-etch-fields.phpHow a custom key reaches the template
- Etch builds the post dataIt assembles the data array that sits behind the this and item keys.
- Your callback receives itIt gets the data array and the post ID, provided it was registered with ten and two.
- You add one keyed arrayYour fields go under a key of your own, as raw values and nested arrays.
- You return the arrayReturn anything else and Etch ignores the filter and keeps the previous data.
- Templates read the new keyUse the key on a page, or through the item name inside a loop.
Meta keys, field plugins or the filter: three routes to a field
There are three ways to put a stored value in front of a template, and the right one depends on how complicated the value is.
The first is the plain meta key. In our loops, {item.meta.key} read a post’s meta field directly. For a text or a number stored in a single meta field, that is the shortest path and it needs no code.
The second is a field-plugin namespace. The documentation lists integrations for ACF, JetEngine and Meta Box, with keys such as {this.acf.field_id} in a template and {item.acf.field_id} in a loop. Here is the honest position. ACF PRO is installed on wpresident.com and we used it for the site’s ad manager, with an options page, field groups defined in code and get_field reads. We did not read those values through Etch keys, so the namespace is documentation-level for us. The documentation also says fields with configurable return formats, such as posts, users and links, return a full object by default, with a feature flag to match the field’s own return setting, and it notes that this changed across the alpha releases. Print the key on a scratch page and look at what you actually get.
The third route is the filter from the previous section, where PHP does the shaping and the template reads a flat, stable structure.
The decision rule is about shape. Use a meta key or a namespace when the value is a single text, number or ID that you print as it is. Use the filter when the value must be shaped: an image field that needs a URL and alt text, a relationship that needs titles and links, a repeater that needs sorting or a limit, any value that needs a fallback. The filter also decouples the template from the storage. If you later move from ACF to plain meta, only the PHP changes and every card still reads the same key. A small guard keeps the page alive if the plugin is switched off.
$hero = function_exists('get_field') ? get_field('hero_image', $post_id) : null;
$data['acme']['hero_url'] = is_array($hero) ? $hero['url'] : '';
That sketch assumes the image field returns an array. With an ID it yields an empty string, a visible failure rather than a fatal error. One more caution: the documentation’s known-issues page describes Etch’s own content-type and custom-field creation area as a work in progress, a proof of concept. We did not use it. Everything in this tutorial reads data created elsewhere.

Escaping, conditions and the markup that comes out
Text deserves its own section, because it is where quiet corruption happens. Etch escapes text content itself. When we pushed text that we had already escaped, the output was double-encoded: readers would have seen the text of an entity where an ampersand belonged. The rule is to store the text as a reader should see it, with plain ampersands and quote marks, and let Etch encode it once. The documentation lists htmlEncode and htmlDecode modifiers. We did not try them alongside Etch’s own escaping, so reach for htmlDecode only when imported data arrives with entities already inside it, and test the result.
The second corruption came from our tooling, not from Etch. NibWP 2.0.0’s converter treated a dollar sign followed by digits as a back-reference in its save step, so a price was stored as a bare zero, and every price on one page was lost until we noticed. The workaround was to put the dollar sign in its own text block. The lesson is general: after any bulk push, read the stored text back and compare it with what you sent, especially prices, percentages and symbols.
Conditions are the other tool for markup that varies. The documentation writes them as {#if}{/if} blocks, and the block type that holds them is etch/condition. The checks it shows are short:
- A boolean check needs no comparison:
{#if user.loggedIn}. - A leading exclamation mark negates:
{#if !user.loggedIn}. - Strict equality is the recommended default:
{#if props.productCategory === "featured"}. - Numbers are written without quotes, so
{#if props.rating >= 3}is a numeric comparison, while a quoted number is treated as text. - Modifiers work inside conditions:
{#if this.categories.pluck("name").includes("News")}tests the post’s category names without a loop.
When the check fails, the content inside is not rendered. The pages we read did not show an else form, so for two outcomes write two conditions with opposite tests. Use a condition for what varies per instance, such as a badge or an optional image, instead of near-duplicate components.
Finally, read the output. We found it clean, with no wrapper elements that we had not authored, so anything unexpected in the source is yours. View the source of a page with a loop and check three things: the item count matches what the preset should return, each item sits in the element you looped, and nothing from an empty condition leaked through.
Scripts on elements, and what prints when
In our build an element could carry a script attribute: an id plus the code encoded as base64. Etch printed it as a deferred module script in the head. We used the mechanism for three things, the header’s search palette, a slider and a dropdown. The attraction is locality. The behaviour is attached to the element it serves, so a page that includes the header receives the header’s script and nobody enqueues anything by hand.
The delivery shapes how you write the code. A module has its own scope, so your variables are not global. It is deferred, so it runs after the document is parsed and selectors can find elements. Module scripts also run in document order. We did not check whether a script prints on a page that lacks its element, or how many copies print when the element sits inside a loop, so write defensively and count the script tags in the source. The sketch below finds every slider, skips any it has already set up and exits quietly when the markup is incomplete.
document.querySelectorAll('[data-acme-slider]').forEach(function (root) {
if (root.dataset.ready) return;
root.dataset.ready = 'true';
const track = root.querySelector('.acme-slider__track');
const prev = root.querySelector('.acme-slider__prev');
const next = root.querySelector('.acme-slider__next');
if (!track || !prev || !next) return;
prev.addEventListener('click', function () { track.scrollBy({ left: -track.clientWidth, behavior: 'smooth' }); });
next.addEventListener('click', function () { track.scrollBy({ left: track.clientWidth, behavior: 'smooth' }); });
});
Keep the real source in a file under version control and encode it when you push, because nobody can review base64 by eye. A module also keeps its variables to itself, so share state between scripts through attributes or custom events. Treat edit access to a script attribute like edit access to PHP: whoever can change it can run code in every visitor’s browser, so review what an agent or an editor plans to attach.
Styles follow a related rule that cost us time. Etch registers styles while blocks render and prints them late in wp_head. In our custom canvas we had to render the content before wp_head ran, or the page styles went missing. If a component looks unstyled only on pages you assemble yourself, check that order before you suspect the CSS.
From script attribute to running code
Failure modes and a verification routine
Most Etch problems in these three areas repeat. The figure lists the eight we would expect, with the first thing to check for each. The common thread is that you should check the stored or printed result, not the screen you built it on.
A routine that kept us out of trouble, whichever way you author:
- Read the page source of one page per type after every change, and look at the loop items, the script tags and whether the styles printed.
- Check the cache state before you judge a change. On our host the cache plugin added an x-xspeed-cache header that read MISS and then HIT (nginx) on a repeat request, and a request with an unknown query string, a random wprnc parameter in our case, bypassed the cache and always returned MISS. That made it a handy way to see a fresh render. Requests with the HEAD method also bypassed it.
- Purge deliberately after changing a component or a list. We never needed a manual purge during the build and cannot vouch for the plugin’s purge rules, so confirm freshness yourself.
- Expect the tooling to fail now and then. Our MCP sessions expired with errors such as Session not found and Missing Mcp-Session-Id, so we re-initialised, and at times we used a small script client in place of the chat client’s connector.
On performance, we ran no controlled benchmarks and have no timing figures to quote. What we saw was that uncached pages were noticeably slower than cached ones when the server was busy, and every loop adds queries to an uncached render, so keep limits modest and the cards light.
Keep a short record of what you changed and which page types you checked. When a loop misbehaves a week later, that record narrows the search to the layer you touched, which is the reach rule from the first section. The last habit is the dry run. A validator that checks structure before writing catches mistakes such as a missing class or a token without a fallback, but it cannot see scope bugs or empty meta fields. Those only show up when you load the page.
Symptoms and the first thing to check
| Likely cause | First check | |
|---|---|---|
| Card shows blank fields | Instance props empty, or an item key typed inside the component | Open the instance and read each prop value |
| Loop prints nothing | Wrong preset name, or the query returns no posts | Count what the same arguments return |
| Wrong number of items | A parameter name does not match, so the default applied | Compare call-site names with the preset |
| Inner loop fields empty | Both loops share one name | Give each loop a distinct name |
| Custom key is empty | Missing argument count, non-array return or a key mismatch | Check the registration and the returned type |
| Page styles missing | Content rendered after wp_head in a custom canvas | Render the content before wp_head |
| Entity text visible | Text was escaped before Etch escaped it again | Push raw text and read the stored value |
| Script does nothing | No matching element, or the script did not print | View the source and log the matched count |
Checklist
- List what repeats on the site and tag each item as a component, a loop with a card, or a shared class before you build any page.
- Build the header and footer components first and reference them from one page of every type.
- Run every push as a dry run first and read the pass and fail list before the suggestions.
- Keep props few: data props for content, a boolean for show or hide, a slot for a block that varies.
- Never type a loop or template key inside a component; map it on the instance.
- Name loop presets for their purpose and give every parameter a sensible default.
- Give each nested loop its own name and keep both limits low.
- Replace a default of minus one with a real number on large sites, then count the items that render.
- Register the dynamic data filter with priority 10 and two arguments, return an array and return raw values.
- Run php -l on every PHP file before you save it, and keep filters in a plugin rather than the theme.
- Test each loop with a post that lacks the field and with a post that has an empty value.
- Push raw text, then read the stored text back, especially symbols and prices.
- Write scripts that wait for parsing, find their elements and exit quietly when they are absent.
- After each change, read the page source for item counts, script tags and styles, and purge the page cache.
Read this next
About this guide. Parts of this guide come from building and running wpresident.com; those parts are marked as such, and everything else is documentation-level guidance. Interfaces and plan limits change, so check the vendor’s current documentation before you act. Not legal, tax or financial advice. See our editorial policy.
Frequently asked questions
What is the difference between an Etch component and a template?
A component is a reusable piece, such as a header, a footer or a card, that pages and templates reference, and editing it updates every place it is used. A template defines the layout for a kind of content, such as every single post. The documentation keeps the two in separate sections. In our build the shared header and footer were components stored as wp_block posts and referenced from every page.
Can I use loop keys such as item.title inside a component?
No. The documentation says never to use loop or template keys directly inside a component, because a component reads only global data and the values passed through its props. Place the component instance inside the loop and fill each prop with a key, for example the title prop with item.title. The card then works the same on a loop, a template or a hand-filled landing page.
What does a parameter written like $limit ?? 6 mean?
It is a placeholder with a default. The call site can pass a limit, and the preset uses that value. If the call leaves it out, the preset falls back to six. In our build, presets stored in the etch_loops option accepted parameters written this way. The documentation adds that when one placeholder appears twice with different defaults, the first default wins everywhere, so use separate names for values that need different defaults.
How do I add a custom field to a loop item?
Register a callback on the etch/dynamic_data/post filter with priority 10 and two accepted arguments. It receives the data array and the post ID. Add your fields under a key of your choice and return the array, because Etch ignores a filter that returns anything else. Then read the field as item.yourkey.field inside a loop, or this.yourkey.field in a template. We added custom fields to loop items this way.
Do I need ACF to use custom fields with Etch?
No. Plain meta fields are readable with item.meta.key in a loop, which worked in our build, and the filter can expose any value from PHP. The documentation also lists integrations for ACF, JetEngine and Meta Box, each with its own key namespace. ACF PRO is installed on our site and powers its ad manager, but we did not read those fields through Etch's ACF keys, so check the current integration page before relying on them.
Why does my loop show nothing, and how do I handle an empty list?
A loop with no results renders nothing by default, so first check the preset name and count what the same arguments return. For a deliberate empty state, the documentation shows a workaround: a second loop that runs only when the data has zero length. It says a more official method is planned, so read the current page. Otherwise design the page so an empty list is acceptable, or hide the heading above it.
Should I escape text before putting it into Etch?
No. Etch escapes text content itself, and in our build text we had already escaped came out double-encoded. Store the text as a reader should see it, with plain ampersands and quote marks. If a tool in between mangles symbols, compare the stored text with what you sent. NibWP 2.0.0's converter, for example, lost text that began with a dollar sign followed by digits until we gave the dollar sign its own text block.
How do I add JavaScript to one component?
In our build an element could carry a script attribute made of an id plus base64-encoded code, and Etch printed it as a deferred module script in the head. Write the code to find its elements after parsing and to exit quietly when they are missing, and check the page source to see how many copies print. Whoever can edit that attribute can run code in visitors' browsers, so control who has access.
Do loops slow a page down?
Each loop on an uncached page runs a query, and nested loops multiply that, so a large limit or a loop inside a loop costs more. We ran no benchmarks and have no timings to quote. Keep limits modest, avoid the all-posts default of minus one on large sites, keep cards light and put a page cache in front.
Can I do all this without the visual builder?
We did. The Etch content on wpresident.com went in through NibWP's API, with components, loop presets, scripts and styles written as data, and we never used the visual canvas. That means we can describe how Etch stores and renders things, but not how the canvas feels. Check what your own setup supports, and try changes on a staging copy first.



