Hello,
My question is: how do I use the spa-sdk to get the data from a document referenced by a component. Ideally someone could provide the methods I need to call, and a simple example.
Here is more context on specifically what I’m trying to do.
I created a few document type (product) and a field group (PDPDetail). The PDPDetail references the product type via a field group Link.
Additionally, I created a component using the Site Development(beta) interface. This component uses PDPDetail as its Content type. I’ve placed this component on a page.
In my front-end (next.js) I am getting back the component in the expected container. I can get the content of the component using this line:
const { product: productRef } = getContainerItemContent<WrappedDetailsProps>(component, page) ?? {};
This gets me back product, which is a document reference. It looks like this if I log it:
{ '$ref': '/page/ub8126d0e4049428cbac7abb8bd328226' }
This seems correct, but from here I don’t know how to get the data from this page. I’ve tried the following:
const productDoc = productRef && page?.getContent<Document>(productRef);
This result of logging this is the following:
DocumentImpl {
model: {
type: 'document',
links: { site: [Object] },
meta: {},
data: {
name: a-product-name',
displayName: 'A Product name',
localeString: 'en_US',
contentType: 'referencespa:product',
id: 'b8126d0e-4049-428c-bac7-abb8bd328226'
}
},
linkFactory: LinkFactory {
mapping: Map(1) { 'internal' => [Function: bound getSpaUrl] }
},
meta: [ comments: [] ]
}
This gets me the document, but I don’t have any of the field values in the document. It makes sense that this would return the document (since that’s what I requested), but I’m not sure what method I should be using. Does anyone have experience with this?
Thanks