Matrix Block Anchor

"Can you send them straight to the pricing bit?"
An editor wants to link to one block partway down a long page: the opening hours, the pricing table, a question in the FAQ. Matrix gives blocks no anchor an editor can see or copy, so they send the link to the top of the page and hope, or they go asking a developer.
Add the Matrix Block Anchor field to your block entry types, output it as the id in your template once, and every block has an anchor. Editors press the copy button beside it and paste the link wherever they need it.

Readable anchors when you want them
By default the anchor is built from the block's ID, so there's nothing for anyone to fill in. If you'd rather have anchors people can read, turn on custom anchors and editors can type their own, like #about-us or #pricing.
Each custom anchor is checked when the entry is saved. It has to start with a letter, use only letters, numbers, hyphens and underscores, and be different from the anchors on the other blocks with the same owner, including blocks added in the same save. If it isn't, the error shows under the field so the editor can sort it out themselves. A block left blank falls back to its auto-generated anchor.
Upgrading and moving blocks
Auto-generated anchors come from the block's ID, so moving blocks around the page doesn't change them. If you're upgrading from a version before 3.0, the legacy separator setting keeps your old #blockIdAnchor-123 links working.
What's in it
| Feature | What it does |
|---|---|
| Automatic anchors | On every block, built from its ID |
| Custom anchors | Editors can set their own, when you allow them |
| Copy button | Works with a keyboard, on revisions, and for people who can only view the entry |
| Card previews | Anchors show in them |
| Validation | Each custom anchor has to be valid, and not used by another block with the same owner |
| Prefix | Change the default blockIdAnchor from the settings or an environment variable |
| Field Usage | A list of where the field is used, with each entry type under its Matrix field |
Matrix Block Anchor is free. It needs Craft CMS 5 and PHP 8.2 or later. From 3.5.0 it works on Craft CMS 6 as well (PHP 8.5, with the craftcms/yii2-adapter package).
Accessibility
What's been checked, and anything that still needs work, is in the accessibility statement.
To install this plugin, copy the command above to your terminal.
This plugin doesn't have any reviews.


