# Run function when cms content loaded

**URL:** <https://forum.finsweet.com/t/run-function-when-cms-content-loaded/2722>\
**Category:** Attributes\
**Created:** [April 4, 2024, 2:34pm UTC](https://forum.finsweet.com/t/run-function-when-cms-content-loaded/2722 "2024-04-04T14:34:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vierless\_julian](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/vierless_julian/32/2147_2.png) [@vierless\_julian](https://forum.finsweet.com/u/vierless_julian)\
**Post date:** [April 4, 2024, 2:34pm UTC](https://forum.finsweet.com/t/run-function-when-cms-content-loaded/2722/1 "2024-04-04T14:34:35Z")

</div>

Is it possible to run a custom callback function once more CMS items are finished loading?

It should be like this:  
1 - User clicks on “load more” button  
2 - Attributes get the items from CMS  
3 - Once they loaded and the call has finished, I run my callback

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [April 8, 2024, 8:07am UTC](https://forum.finsweet.com/t/run-function-when-cms-content-loaded/2722/2 "2024-04-08T08:07:01Z")

</div>

Hey @vierless_julian! You cann use the CMS Load API callback to run any code after the solutions has loaded successfully!

```js
window.fsAttributes = window.fsAttributes || [];
window.fsAttributes.push([
  'cmsload',
  (listInstances) => {
    console.log('cmsload Successfully loaded!');

    // The callback passes a `listInstances` array with all the `CMSList` instances on the page.
    const [listInstance] = listInstances;

    // The `renderitems` event runs whenever the list renders items after switching pages.
    listInstance.on('renderitems', (renderedItems) => {
      console.log(renderedItems);
    });
  },
]);

```

You can read more here!

> **[CMS Load API for Webflow](https://finsweet.com/attributes/api/cms-load)**
>
> Write javascript to customize CMS Load with Attributes API. Powerful load options for Webflow CMS Collection Lists.

---

<div class="post-metadata">

**Author:** ![vierless\_julian](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/vierless_julian/32/2147_2.png) [@vierless\_julian](https://forum.finsweet.com/u/vierless_julian)\
**Post date:** [April 8, 2024, 3:51pm UTC](https://forum.finsweet.com/t/run-function-when-cms-content-loaded/2722/3 "2024-04-08T15:51:22Z")

</div>

Ok, got it. In my case I want to lazy load iframes in my items. Therefore I need to know when I loaded the next ones. So if I just use the callback, then I could not get the new items to update.

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [April 10, 2024, 7:28am UTC](https://forum.finsweet.com/t/run-function-when-cms-content-loaded/2722/4 "2024-04-10T07:28:17Z")

</div>

Yes, the `renderitems` is fired every time new items are rendered on the page and you can loop over the `renderedItems` loading the iframe on them. If you already have the code to load the items I can share how it should look like
