### Show a live HTML preview under a field by substituting the current value into a per-field template.

(Image content)

[

**This is a Community Plugin!** Learn how create your own plugin, or copy and remix existing ones in our documentation

](https://www.datocms.com/docs/plugin-sdk/introduction.md)

## Field value preview

(Image content)

A DatoCMS field addon that renders a live preview under a field by substituting the current value into an HTML template you define.

Editors keep the normal field UI and validation. You configure how the value should look when rendered — useful for URL embeds, color swatches, maps, and other “what will this become?” checks inside the CMS.

## What it looks like

(Image content)

## Requirements

-   Field type is one of the supported types below
-   Assign **Field value preview** as a field addon in **Presentation**
-   Configure **Preview HTML** with a `{{value}}` placeholder

## Supported field types

| Field type | What `{{value}}` receives (before extract pattern) |
| --- | --- |
| Single-line string, Multiple-paragraph text, Slug | The text as entered |
| Integer, Float, Boolean | String form of the number/boolean |
| Date, DateTime | The stored date/time string |
| Color | CSS hex (`#rrggbb`) or `rgba(...)` when alpha < 1 |
| Location | `latitude,longitude` |

Not supported: External video (this plugin replaces that workflow with a URL string field), JSON, Modular Content, Structured Text, Single Block, assets, links, SEO.

## Preview HTML

Paste the HTML that should appear under the field. Put `{{value}}` wherever the current field value (or the extracted piece of it) should be inserted. The value is HTML-escaped before substitution.

### YouTube URL on a string field

Field value example: `https://www.youtube.com/watch?v=wzQWBGkzxSI`

**Extract pattern**

```plaintext
(?:youtube\.com/(?:watch\?.*v=|embed/|shorts/)|youtu\.be/)([\w-]{11})
```

**Preview HTML**

```html
&lt;iframe width="560" height="315" src="https://www.youtube.com/embed/{{value}}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen&gt;&lt;/iframe&gt;
```

### Color swatch

```html
<div></div>
```

### Raw value

If the field already stores something embed-ready, leave the extract pattern empty:

```html
&lt;iframe  width="100%"  height="315"  src="{{value}}"  title="Embed preview"  frameborder="0"  allowfullscreen&gt;&lt;/iframe&gt;
```

## Extract pattern

Optional JavaScript regular expression.

| When | What `{{value}}` becomes |
| --- | --- |
| Pattern is set | Capture group 1, or the full match if there is no group |
| Pattern is empty | The normalized field value |
| Value does not match | An error under the field instead of a blank preview |

## Preview height

Optional. Leave empty to **auto-size** the preview to its content (including embeds that load asynchronously, like X cards). Set a pixel height only when you need a fixed frame.

## Empty fields

When the field is empty, the addon shows a short note that the preview appears once a value is present. It does not invent a default.

## Install

### From npm

1.  In the DatoCMS project, open **Settings → Plugins** and add `datocms-plugin-field-value-preview`.
2.  On a supported field, open **Presentation**, add the **Field value preview** addon, and paste your preview HTML (and optional extract pattern).

### Local development

```sh
pnpm installpnpm --filter datocms-plugin-field-value-preview dev
```

Then add a **private plugin** whose entry point is `http://localhost:5175/`. Use Chrome or Firefox; Safari does not handle localhost plugin iframes well.

If you previously installed this plugin under the old `html-field-preview` name/URL, remove that private plugin (or switch its entry point) and re-add the addon on your fields — extension IDs changed with the rename.

To keep a working Marketplace install untouched, duplicate it and point only the copy at localhost.

## Publish

```sh
cd plugins/field-value-previewpnpm publish
```

The package publishes `dist/` plus the marketplace images in `docs/`. Bump `version` before each release. Existing DatoCMS installs do not update themselves; use **Switch to a different version**.