A Fragment block for the Aurora editor in Plone Blicca.
A fragment is a static piece of HTML, usually cut straight from the design mockup: a contact box, a seal, a call-to-action banner, a partner-logo strip. Your theme ships it as a file in a folder it registers with one line of ZCML. Editors then pick it from a list and drop it into a page. The markup is rendered exactly as it is in the file, both in the editor and on published pages.
Editors never edit the markup. When the file changes, every page using the fragment updates on the next deployment.
Add collective.fragmentsblock to your project dependencies and install it
in the Plone add-ons control panel.
Requirements: Plone 6, Python 3.10 or newer, and a plone.blicca.auroraeditor
that ships block-api 2.0, the Plate 53 editor. The editor waits for this
block to fetch its fragments before it renders.
This package only provides the block. Fragments come from your own add-on, typically the theme package. See the next section.
Fragments live in a folder of your add-on, one HTML file per fragment. The server reads the files when it renders classic pages, and the editor fetches the same files from the server when it opens. Nothing is built, bundled or copied.
src/my/theme/
├── fragments/
│ ├── contact-box.html
│ └── seal.html
└── configure.zcml
The file name is the fragment id. Ids must match ^[A-Za-z0-9][A-Za-z0-9_-]*$
and are unique across the whole site, so prefix them if more than one
add-on may provide fragments. A file whose name is not a valid id is skipped
with a warning.
Register the folder in your configure.zcml:
<!-- my/theme/configure.zcml -->
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:fragments="http://namespaces.plone.org/fragmentsblock">
<include package="collective.fragmentsblock" file="meta.zcml" />
<fragments:folder directory="fragments" />
</configure>directory is relative to your package. The folder is registered under
your package name. Pass name="..." if you need another one. A folder that
does not exist is an error at startup, not an empty picker.
That is all. Restart Plone and the fragments appear in the picker.
Editors pick a fragment by its title. Put it in a comment on the first line of the file:
<!-- title: Contact box -->
<aside class="contact-box">
...
</aside>Without that comment the title is derived from the file name:
contact-box.html becomes "Contact box", partner_logos.html becomes
"Partner logos". The comment is part of the markup and is rendered with it;
browsers ignore it.
- Open the page in the Aurora editor.
- Type
/and choose Fragment from the slash menu. - In the block settings, pick the fragment from the Fragment list.
The fragment renders immediately. Two more settings control placement:
- Block width:
narrow,default,layoutorfull. Defaults todefault. - Background: a named colour slot from your theme's palette, such as
GreyorAccent. The field only appears if the theme registers a palette.
Both paint the block wrapper around the fragment, not the fragment itself.
If a fragment's add-on gets uninstalled, the editor shows a note in place of the block and the published page renders nothing there. Pages never break.
- Fragment HTML is trusted. It ships with your add-on and is not
sanitised. A
<script>in it runs on the published page. - Variables. Markup may contain
${name}tokens. They are filled from the block'svariablesmapping, HTML-escaped, with missing names rendered empty. There is no editor UI for this yet. The mapping can be set through the REST API or an upgrade step. For now, if a fragment needs different values on different pages, ship one fragment per variant. - Wrapper. Both the editor and the server wrap the markup in a
<div class="block-fragment">. Mockup HTML written for a grid or flex parent needs to account for that. - The editor fetches
@fragments. When the editor opens, the fragment block requests<site>/@fragmentswith the session cookie and registers what comes back before the first render. The list is every provider'srecords(); where two providers use the same id, the one whose name sorts first wins, on both surfaces. If the request fails, the block stays available with an empty picker and existing fragment blocks say so instead of rendering nothing. - Other sources. A folder of files is the stock provider. For anything
else, register a named utility that implements
IFragmentsProvider:get(fragment_id)returns the HTML orNone, andrecords()lists every fragment as{"id", "title", "html"}. - Registering from JavaScript still works. An Aurora add-on may register
fragments itself, with
registerFragment(config, {id, title, html})from the npm package@plone-collective/aurora-fragment-blockor with a bareconfig.registerUtilityof typecollective.fragmentsblock.fragment. The server then needs a matching provider, or the fragment renders only in the editor.
The editor half lives in bundle-src/ and is built into the Python
package's static/ folder. The build output is committed.
cd bundle-src
pnpm install
pnpm build
pnpm testPython tests:
uv run --extra test pytestGPLv2 for the Python package, MIT for the npm package.
Maik Derstappen, derico.de, md@derico.de