Replies: 2 comments
-
I think you can fetch the data from server in view init of the component 🤔 https://grapesjs.com/docs/modules/Components.html#lifecycle-hooks |
Beta Was this translation helpful? Give feedback.
-
I have done this already, so I wanted to share an overview of our approach. (I'm not sharing the whole code... just a simplified version of the flow, so beware of errors if you just copy and paste this code) I have a CollectionList component, with a Source trait (datasrouce attribute) with different options which are mapped to endpoints on our API.
Here I share some of those sync functions:
On the other hand, my text components all extend from 'dynamicText', which on init() check if they are children of CollectionItem.
By the way, I have made this work for all kind of components, such as images with dynamic sources, videos, etc. I'll share a video of the working editor on a later comment. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to create a dynamic component that gets its info (text and images) from an api dynamically, but you can still style each element, reorder elements, etc.
For example, a Product List component, that when mounted ( editor.on('component:mount') ) fetches data and adds the corresponding components inside.
My main issues when trying this are:
It's a dynamic REPEATER, that means that I will get as a result an array of Products, and will append each one of them inside the Product List component. So far so good, but I need this (now independent) Product components so by in sync with each other. If I reorder the components INSIDE one Product, all Products should do the same.
Also... since I am doing editor.on('component:mount') and "manually" adding the components; whatever changes I made are unmade when I reload (because its re-mounting and its setting the inner components once again. Style changes are preserved (at least while working with private classes and componentsFirst: false)
Finally... I don't really need to save all of the child components of my main dynamic element (Product List), what I would like instead is to save a Template, that when exported and viewed from a browser (the published website) it makes the api call and appends all the content based on that template. Basically I don't need to overload the save/load in the editor when having 500 products.
I hope I was clear enough... for those of you familiar with Webflow, it's basically the CMS Collection Element behaviour that I am trying to replicate
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions