prelo
Plugins / Image gallery

Image gallery

Filterable gallery with lightbox, fed straight from the media library.

Agithub.com/anderdigitalMediaprelo >= 0.4Updated Jun 2026Official
Use this plugin
1
2
or point your agent at the spec:
Your agent reads the spec and writes the code into your project. Review the diff like any change.

What this adds

A responsive image gallery the client curates from Studio: pick images from the media library, caption them, tag them, done. Visitors can filter by tag and open any image in a full-screen lightbox. Thumbnails are served resized — the page never ships full-resolution files.

How it works

The gallery is a page section: a repeatable list of images with captions and tags, defined in cms.config.js. The client composes it onto pages like any other section. The frontend renders a grid using the CMS's on-the-fly image resizing (?w= on any upload URL) and a dependency-free <dialog> lightbox.

The spec your agent followsexpand ▾
You are adding a gallery section to a Prelo project. Read `prelo docs sections` and `prelo docs config` if unsure.

1. **Section definition.** In `cms.config.js` under `sections:`:

   ```js
   gallery: {
     fields: {
       heading: { type: "text" },
       layout:  { type: "select", options: ["grid", "masonry"], studio: "variant" },
       images:  { type: "list", of: {
         image:   { type: "image", required: true },
         alt:     { type: "text", required: true },
         caption: { type: "text" },
         tag:     { type: "text" },
       }},
     },
   },
   ```

   The generic Studio renders the list as a repeater with media-library pickers automatically — no Studio work.

2. **Renderer.** Add a `gallery` renderer wherever the project renders sections/blocks:
   - One-process site: pass it in the `renderBody(body, { gallery: (block) => … })` renderer map.
   - Next/Astro frontend: a `Gallery` component in the section-rendering switch.

3. **Grid.** Render an image grid (CSS grid for `grid`, CSS columns for `masonry`). Each thumb is an `<img>` with `src="{upload}?w=640"`, `srcset` at 480/640/960, `loading="lazy"`, the required `alt`, and the caption underneath in the project's muted text style.

4. **Tag filter.** Collect the distinct non-empty tags in the section; if there are 2+, render a row of filter buttons ("All" + each tag) above the grid. Filtering is client-side (hide/show, no relayout jank — keep grid items in the DOM and toggle a hidden class). Skip the row entirely when tags aren't used.

5. **Lightbox.** Use a native `<dialog>`: clicking a thumb opens the full image (`?w=1600`), caption below, prev/next buttons and arrow-key navigation across the *currently filtered* set, Escape and backdrop-click to close. Trap focus while open; restore focus to the opening thumb on close. No third-party library.

6. **Progressive enhancement.** Without JavaScript the grid must still render and each thumb link directly to the full-size upload.

7. **Verify.** `prelo check`; in Studio add a gallery section with 4+ images and two tags; confirm filter + lightbox + keyboard nav; confirm the network panel shows resized thumbs, not originals.

After it's built

The client edits the gallery in Studio like any section: add images from the media library, drag to reorder, set captions and tags. New tags appear as filters automatically.