I have requirement in AEM React SPA project, I have to display image and metadata on page
to meet the above requirement I used out of box image component with this I can display the image on page, I want to display the metada as well on the page .
to meet the above requirement I used out of box image component with this I can display the image on page, I want to display the metada as well on the page .
You can check the fields being exposed via model.json
{
"src": "/content/dam/my-site/avatar.jpg",
"alt": "Profile picture of John",
"title": "John's Avatar",
"caption": "This is John's profile image.",
"uuid": "12345-abcde"
}
on the react side something like this could be done. Make the necessary imports
const ImageWithMetadata = (props) => {
if (!props || !props.src) {
return null;
}
return (
<div className="image-with-metadata">
<img src={props.src} alt={props.alt || ''} title={props.title || ''} />
<div className="metadata">
{props.title && <h3>{props.title}</h3>}
{props.caption && <p>{props.caption}</p>}
{props.alt && <p>{props.alt}</p>}
</div>
</div>
);
};
ImageWithMetadata.defaultProps = {
src: '',
alt: '',
title: '',
caption: ''
};
// Map to AEM core image component resource type
export default MapTo('core/wcm/components/image/v2/image')(ImageWithMetadata);
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.