HTML and limits
This page shows you how a component is written in the HTML panel, and where components stop.
In the HTML panel
A placed component reads as a Twig embed, with its values and the slots it fills:
{% embed 'card' with { title: 'Our services', featured: true } %}
{% block actions %}
<a href="/quote">Get a quote</a>
{% endblock %}
{% endembed %}
- The name is the pattern's slug.
withholds one value per property. A text is quoted, a number andtrueare not, andpost.titlepasses dynamic data. A quoted text may hold dynamic data:'By {{ user.name }}'.onlyafter the values keeps the page's variables out of the pattern:{% embed 'card' with { title: 'Hello' } only %}.
Without only, the pattern also reads the variables the page sets above it. A variable the pattern sets ends with the pattern: it never changes one of the page's.
Common mistake
Forgetting the quotes around a text. title: 'Services' passes the word. title: Services looks for data named Services.
Limits
- Synced patterns only. A pattern that is not synced is placed as a copy of its blocks, so it takes no property and no slot.
- Patterns that are not public. A draft, a private pattern or one with a password shows in the editor, with a warning in the sidebar. It shows nothing on the site.
- A pattern inside itself. A pattern cannot place itself, directly or through another pattern.
- Patterns with pattern overrides. A page that already changed a pattern through WordPress's own overrides keeps those values, and does not get the properties until the values are reset. The Component panel warns you when a pattern with properties holds such blocks.
- A property named like built-in data.
image,author,post,user,term,site,postsandattachmentare data Unblock already has. When a page sets no value, the property can read that data instead of its default. Use another name, such asphoto.
Translation
WPML and Polylang translate these values with the page:
- the text a page sets in a Text property
- the link it sets in a Link property, unless that link holds
{{ }}
A select's option, a color, a number and an image are not sent, since the pattern compares them.
- A property the pattern compares (
tone == 'dark'): give it the type Select. Left as a Text, its value would be translated and would no longer match. - A property's default lives in the pattern. Write it
__('Card title')for it to be translated. - The pattern itself is translated as any synced pattern. A translated page shows the translation of the component's pattern.
Next steps
- Save patterns: take a component to another site
- Patterns and the AI: have the AI place a component, pass its values and fill its slots
- Multilingual: how translation works in Unblock