Is it possible to match the slug for the page in the Connected Data query editor dynamically or do I need to make this call in code?
Hi,
My name is Veronika and I am a Customer Engineer here at Builder.
Yes - you can match the slug for a page dynamically within the connected data in Builder. This will allow you to filter the data that is shown based on the page’s URL or slug without needing to write extra code outside of Builder Visual Editor tools.
Here’s something that I am currently working on locally and how I used the slug to filter out the entry I wanted.
Let me know if you have any other questions,
Thank you.
But aren’t you providing a hard value and not a dynamic one?
My apologies for the above answer, I misread the question.
If you want to have some dynamic value, you can fetch the data in the custom code section of the data tab.
This is an example code that you could use, just make sure you customize the code to fit what you are trying to achieve.
async function main () {
const response = await fetch(`https://cdn.builder.io/api/v3/content/page?apiKey=${YOUR_API_KEY}&query.slug=${SOME_DYNAMIC_SLUG}`)
const data = await response.json()
state.pageData = data;
}
export default main();
Let me know if you have any further questions,
Thank you.