Repository navigation
Matrix: a page preview view, where clicking a block opens it in a slideout #20236
Unanswered
wmdhosting
asked this question in
Ideas
Replies: 1 comment
|
Update after #14298 was answered today with slideout Live Preview (#19964):
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The idea
Matrix fields already let authors choose how nested entries are shown (Cards, Card grid, Blocks, Index). For page builders, the view authors actually think in is the page itself. We'd like a Preview switch on the field, next to the existing view:
The same markers would make blocks clickable inside Live Preview, which is what #2811 asked for in 2018. Craft 6 now has every piece (Live Preview, element editor slideouts in the preview pane, reorder buttons), only the glue is missing.
Templates would opt in by marking blocks, e.g. a Twig helper that prints attributes only during a CP preview:
{% for block in entry.pageBuilder.all() %} <section {{ previewAttrs(block) }}>…</section> {% endfor %}Why
Pages built from many large blocks are hard to read as cards or collapsed blocks, and dragging a tall block past others is awkward. Authors want to see the page, point at the part they want to change, and edit it there. Front-end editing tools do this for the public site; this would bring it into the CP, with Craft's own editor, drafts and permissions.
What we built to try it
A field layout UI element above the Matrix field renders the page in an iframe (blocks wrapped in
data-*markers), and a script in the previewed page:craft:edit-elementon the parent window to open the slideout,craft-reorderon the block'scraft-reorder-buttonin the editor (found byli[data-id]in Cards view, bydata-keyinside the list's shadow root in Blocks view),craft:element-savedto reload, and asks Live Preview to refresh withcraft:refresh-previews.It works, but it leans on internals that can change in any release.
Screenshots
Smaller hooks that would let plugins build this cleanly
If a native view isn't planned, these would make it a supported plugin feature:
craft:edit-elementas a public event, or a@craftcms/cpfunction).craft:move-nested-element, ormoveNestedElement(id, direction)), and events for nested reorder, add and delete.Matrix::blockActions()is private, so adding "Open in a slideout" needs aMatrixsubclass bound in the container, and Craft then writes the subclass into project config when the field is saved.Entry::previewTargets()returns none for nested entries, so Preview isn't offered on a block's own edit page or in its slideout.All reactions