Hi, I’m migrating a react app into Builder. I’m currently with the blog. The issue is that I have all the blogs in a page model (because each one has a different path /blog/example), but I can’t find a way to then list all the blogs with their data in the blog index page (/blog).
Is there a way to get the data from a page model? Thanks
Hi @emiliano , thank you for the question and welcome to the Forum!
There are a few ways that you could achieve this…we actually have a walkthrough for setting up a blog with ReactJS here: Creating a blog in Builder - Builder.io
I think particularly the List Articles page mentioned at this section could be helpful for you if you want to build out this page within your code base.
If, however, you want to build this pages purely within the Visual Editor, that is also possible! Are these blog pages saved as a section or data model? If so, you can always pull that data to your page and set up data bindings to create article tiles for each blog post. This walkthrough shows how to pull in data and bind it to elements on the page: Connecting dynamic data in Builder's Visual Editor
If they are saved as page models then you can also achieve this, but would probably need to set a fetch() call to our content api within the Custom JS + CSS window, add it to state, with something like this:
await fetch(builderContentAPIUrl)
.then(res=>res.json)
.then(data => state.articles = data)
Which you would then iterate over and bind the content much like in the linked walkthrough above.
Let me know if either of those options work for you or if you need further help / explanation of any specific steps, I am happy to help!
Thank you very much Tim! this is so useful!
Hi @TimG , it infuriates me that you can’t pull page model data in like you can a data model. A blog listing is a perfect example, or latest blogs. Would love to know the reason behind it someday.