@contentstack/delivery-plugin-interstack-reference
v1.0.0
Published
This is a SDK plugin for Interstack Reference App. This plugin fetches the referenced entry data through a custom field to display the content on your Contentstack website. Contentstack has its own [Javascript Delivery SDK](https://www.contentstack.com/do
Downloads
28
Readme
Interstack reference
This is a SDK plugin for Interstack Reference App. This plugin fetches the referenced entry data through a custom field to display the content on your Contentstack website. Contentstack has its own Javascript Delivery SDK that supports this plugin which can be used to fetch the content for your page from Contentstack for Interstack Reference app.
About Interstack Reference App
Interstack Reference App allows you to fetch referenced entries in the custom field of your content type and use the entries data across multiple stacks.
How to use this plugin
To use this plugin, you need to add the includeReference call within your SDK.
- Install the interstack plugin from the NPM library.
npm install @contentstack/delivery-plugin-interstack-reference
- Import the plugin
const InterstackPlugin = require("@contentstack/delivery-plugin-interstack-reference");
- Create an Interstack Reference App plugin as shown below. You must provide the stack API Key and Delivery Token of all the referred stack.
function main() {
const interstack = new InterstackPlugin([
{
api_key: "blt53ed****888672",
delivery_token: "cs9b84666******c49f48",
},
{
api_key: "blt7a********053b38",
delivery_token: "cs47178********e5ba15e",
},
]);
}
- Now, create a new stack and call the plugin within this function. This will basically fetch the plugin details and attach it with the Contentstack data.
const Stack = contentstack.Stack({
api_key: "bltc18****3d910",
delivery_token: "csc030300****8914a00",
environment: "dev",
plugins: [interstack], // Here we have added the plugin
});
- To select the entry which is being used in the custom field, you will have to create a query and add the field_uid of the custom field inside includeReference() method.
const query = Stack.ContentType("cs1")
.Query()
.includeReference("custom")
.toJSON();
- Now, to find the content you need to add the below function:
query
.find()
.then((res) => {
console.log(JSON.stringify(res, null, 2));
})
.catch((err) => console.error(err));
Example Code:
const InterstackPlugin = require("@contentstack/delivery-plugin-interstack-reference");
function main() {
const interstack = new InterstackPlugin([
{
api_key: "blt53ed***8672",
delivery_token: "cs9b84666****efc49f48",
},
{
api_key: "blt7ae6****53b38",
delivery_token: "cs471781****7e5ba15e",
},
]);
const Stack = contentstack.Stack({
api_key: "bltc1875****b3d910",
delivery_token: "csc030300***8914a00",
environment: "dev",
plugins: [interstack],
});
const query = Stack.ContentType("cs1")
.Query()
.includeReference("custom")
.toJSON();
query
.find()
.then((res) => {
console.log(JSON.stringify(res, null, 2));
})
.catch((err) => console.error(err));
}