getEntriesByCollection available in previews
- Dominant language
- JavaScript
- Stars
- 19.4k
- Forks
- 3.1k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
I do not see this feature request opened, but may have missed something. It is similar to the request on the answers.netlify.com site: https://answers.netlify.com/t/access-entries-data-from-netlify-cms-events/15985.
**Is your feature request related to a problem? Please describe.**
Producing a proper preview in the preview pane when an item contains a reference to another collection (relation widget) is currently not possible, as access to the external collection isn't available.
**Describe the solution you'd like**
**Describe alternatives you've considered**
For creating previews, it would be nice to have access to other collections, as the relationship field points to them, and to create a decent preview, access to the collection referenced by the relationship field is crucial. Something like:
`const otherEntries = getEntriesByCollection('some-collection')`
**Additional context**
I would use this in a renderer as follows:
var AtlasLandingPreview = createClass({
render: function() {
const entry = this.props.entry;
const getAsset = this.props.getAsset;
const widgetFor = this.props.widgetFor;
const widgetsFor = this.props.widgetsFor;
const allNewsArticles = getEntriesByCollection('news');
return h('ul', {className: 'content'},
widgetsFor('articles').map(function(article,i) {
// a search of the allNewArticles collection would be performed here, looking for a matching article.uuid in my case
var foundArticle = findArticleByUUID(article);
// other fields like foundArticle.thumb, foundArticle.date, etc could be accessed here
return h('li', {}, foundArticle.title); // note: my articles aren't stored by title, but by UUID
})
);
}
});
(Of course some of that code is just sudo-code)
Contributor guide
Assessment
This issue has not been assessed yet.