I noticed that when I add a video link in the CMS it creates it as an embed in the editor. I attached a screenshot where it provides the Source as the “link from video” referencing the CMS.
Is their documentation for, or is it possible to do this with other things when writing custom code to reference the Webflow CMS? For example, if I wanted to write a function that is triggered upon clicking a button within a CMS div, could I write a function that targets the specific CMS ID attached to that particular CMS item?
You don’t need to reference an ID, if you want to run a code for each item inside a collection list, you can add the embed inside the dynamic item and take advantage of document.currentScript (supported by all browsers but IE, but who cares is deprecated nowadays ) it will give you a reference to the script html element itself. So you can make a query on the closest .w-dyn-item and from there make your manipulation!
Hey @pietrofalco thanks for your answer- does this apply to running code on CMS items within the CMS itself?
I’m trying to set it up so when a collection field is switched to “Approved” by an admin in the CMS, it triggers a flow. At the moment can’t figure out how to do this either in Flows or in custom code.
Logic supports form triggers and webhook triggers.
In theory, you could setup an webhook-triggered logic flow, and then register that webhook with the Webflow API to detect collection_item_changed events. From there, you check for that approved state and run your flow logic accordingly.
In practice, you have at least two challenges;
When the webhook fires, you’ll get the current state of the CMS item, not the previous state. That means that if someone updates it, you cannot inherently detect if that switched state just happened now, or if the switched state happened a year ago. Depending on what you’re trying to do, that might matter. If so you’ll need to rethink your approach. **
Logic executions cost the same as a form submission. I believe that’s true for webhook-triggered flows as well. Once your form submissions are used up in a month, the cost per execution is $0.01 usd per execution. That may not seem like much at all but depends entirely on what you’re trying to automate here. That’s much more expensive than a ChatGPT v4 API call for example.
** One approach is to think of the switch like a button. When you see it toggled on, your logic runs, but then it updates the record to toggle that button off, and to set a separate field with the current timestamp. That let’s you know that your process has already been run on this item, and exclude it later from accidental re-processing.
That’s fairly straightforward and an already a solved problem.
Use Webflow Webhooks:
When an admin switches that field to approved, the Webhook (once setup) will trigger a workflow automation with whatever service you like (Make / Integromat / Zapier / whatever…).
You won’t need to create any custom code for this.