Includes a new options chain method to add the full media to the Objects payload on all metadata fields. This enables easier use of alt_text, metadata and other helpful media data.
const { object } = await cosmic.objects
.findOne({
type: 'vehicles',
slug: 'ferrari',
})
.props('slug,title,metadata')
.depth(1)
.options({
media: {
props: "alt_text" // all | alt_text | name | id ... etc see media model for all available props https://www.cosmicjs.com/docs/api/media#the-media-model
}
});
What's new
Includes a new
options
chain method to add the full media to the Objects payload on all metadata fields. This enables easier use ofalt_text
,metadata
and other helpful media data.Before
So instead of this:
Which returns:
With this update
You can now do:
Returning all available media data:
How it works under the hood
url
orimgix_url
properties.media.find
method and the intendedprops
declared in the options.Note: this will use another API request media data for each object and may slow down the response time.