Teaser
Developer Reference
Schema
Pass this object inside the blocks option when calling initBridge() to register this block type with the admin UI. See Custom Blocks for the full setup guide.
{
"teaser": {
"fieldMappings": {
"@default": {
"@id": "href",
"title": "title",
"description": "description",
"image": "preview_image"
}
},
"blockSchema": {
"properties": {
"href": {
"title": "Target",
"widget": "object_browser",
"mode": "link"
},
"title": {
"title": "Title"
},
"description": {
"title": "Description",
"widget": "textarea"
},
"preview_image": {
"title": "Preview Image",
"widget": "image"
},
"overwrite": {
"title": "Overwrite target content",
"type": "boolean"
}
}
},
"schemaEnhancer": {
"childBlockConfig": {
"defaultsField": "itemDefaults"
}
}
}
}JSON Block Data
Example JSON as stored in the Plone content API. This is the data structure your component will receive in the block prop.
{
"@type": "teaser",
"href": [
{
"@id": "/news/my-article",
"title": "My Article",
"description": "A short summary of the article",
"hasPreviewImage": true
}
],
"title": "Custom Title",
"description": "Custom description overriding the target",
"preview_image": "data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27400%27 height=%27300%27%3E%3Crect width=%27100%25%27 height=%27100%25%27 fill=%27%2399bbdd%27/%3E%3Ctext x=%2750%25%27 y=%2750%25%27 fill=%27white%27 text-anchor=%27middle%27 font-size=%2718%27%3ETeaser%3C/text%3E%3C/svg%3E",
"overwrite": true
}Component
Render component for your frontend framework. Add this to your block renderer's switch/map so it handles this @type.
function TeaserBlock({ block }) {
const hrefObj = block.href?.[0] || null;
const useBlockData = block.overwrite || !hrefObj?.title;
const title = useBlockData ? block.title : hrefObj?.title || '';
const description = useBlockData ? block.description : hrefObj?.description || '';
const href = hrefObj?.['@id'] || '';
const imageSrc = block.preview_image
? (typeof block.preview_image === 'string' ? block.preview_image : block.preview_image['@id'])
: (hrefObj?.hasPreviewImage ? `${href}/@@images/preview_image` : '');
if (!href) {
return (
<div data-block-uid={block['@uid']} className="teaser-placeholder">
<p>Select a target page for this teaser</p>
</div>
);
}
return (
<div data-block-uid={block['@uid']} className="teaser-block">
{imageSrc && <img data-edit-media="preview_image" src={imageSrc} alt="" />}
<h3 data-edit-text="title">{title}</h3>
<p data-edit-text="description">{description}</p>
<a href={href} data-edit-link="href">Read more</a>
</div>
);
}