Hi @naik34,
Thanks for the post. If you are looking for a way to give each dynamic item it’s own ID, then try this:
Step 1: Create a field in the CMS to act as the dynamic ID, and give a sequenced number to each post, starting with zero:
Step 2: Create a dynamic list on your page, which is sorted by the dynamic ID, from smallest to largest:
Step 3: Give a an ID to your Dynamic Items element, I would call it “dynamic-items”:
Step 4: Insert an Embed Widget, directly below the Dynamic Item element, so that it comes before other content.
Step 5: In the Embed widget, paste the following code, inserting the Dynamic ID where indicated in the screenshot:
First the code:
<script>
var x = document.getElementById("dynamic-items").querySelectorAll("div.dynamic-item");
x[dynamic-id-goes-here].setAttribute("id", "item-dynamic-id-goes-here");
</script>
Where it says “dynamic-id-goes-here”, replace that with the Dynamic ID field from the CMS:
The custom code will only be run on the published site after saving the custom code embed, and you have set your dynamic ID field for each record starting with 0, then each dynamic item will get it’s own ID, with that being set dynamically based on the ID of the Dynamic ID field.
Here is an example site:
Here is the public site link: https://webflow.com/website/Using-Dynamic-IDs-with-Collection-Items
The ultimate solution will be for Webflow to provide a unique ID for each dynamic item automatically, but that feature is not added yet, so without the workaround, all dynamic items get the same ID (if that is set in the designer on the dynamic item element).
I hope this helps!