The actual code you write will depend on the framework you choose. You can look at these examples to help you:
Before you dive into the steps, here's what your frontend ends up doing.
To make a site editable with Hydra you break a page into:
- Type, title, icon etc. so the user can pick from a menu. - Fields: string, image, link etc. each with their own sidebar widget. - slate is a special field that contains JSON for a paragraph, heading etc. - blocks fields let a block hold other blocks.
When the page loads inside Hydra's edit iframe, you initialise the bridge and declare your blocks; otherwise you render normally from the API:
Page data ends up shaped like this:
Then you augment the rendered HTML with data- attributes (or <!-- hydra ... --> comments) so Hydra can find your blocks and editable fields:
The steps involved in creating a frontend are roughly the same for all these frameworks:
Create a route for any path which goes to a single page.
For example, in Nuxt.js you create a file pages/[..slug].vue.
The page has a template with the static parts of your theme like header and footer. You might also check the content type to render each differently.
On page setup, take the path and make a REST API call to the contents endpoint to get the JSON for this page.
@plone/client for this- Note: this is just a wrapper on the REST API rather than a server-side implementation, so it's not more efficient than using the REST API directly
In your page template, fill title etc. from the content metadata.
Block component that takes the id and block JSON as argumentsBlock component recursivelyblocks_layout list and render a Block component for eachSeveral helper functions get reused in many blocks:
- You may also decide to use your framework or hosting solution for image resizing
If your REST API call returns an error, handle this within the framework to display the error and set the status code.
If you choose to allow Volto's built-in Search Block for end-user customisable search:
Form-block is a plugin that allows a visual form builder:
Hydra separates your production frontend from the editing experience, which gives you choice in how each is deployed.
The simplest setup — your frontend handles both production and editing:
This gives you all visual editing features including inline text editing, drag and drop, and realtime preview.
Get the speed of static generation while keeping visual editing. Deploy two versions of the same frontend:
The default Hydra demo uses exactly the SSG / SSR pattern above:
For most frameworks, switching between SSG / SSR and SPA is just a config toggle, so you get the best of both worlds with minimal effort.