# Trigger script when using CMS load

**URL:** <https://forum.finsweet.com/t/trigger-script-when-using-cms-load/1601>\
**Category:** Attributes\
**Created:** [July 8, 2023, 5:28pm UTC](https://forum.finsweet.com/t/trigger-script-when-using-cms-load/1601 "2023-07-08T17:28:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobiastorjusen](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tobiastorjusen](https://forum.finsweet.com/u/tobiastorjusen)\
**Post date:** [July 8, 2023, 5:28pm UTC](https://forum.finsweet.com/t/trigger-script-when-using-cms-load/1601/1 "2023-07-08T17:28:29Z")

</div>

Hi,

I’m trying to build a winelist using Webflow CMS. The structure I’m going for is as follows:

Country (H1)  
Region 1 (H2)  
Wine 1  
Wine 2

Region 2 (H2)  
Wine 3  
Wine 4

I’ve got a working example of the setup at www.restaurantiris.no/winelist

I’m using a custom script to hide the headers for each item (the wines) if the region or country equals the last items country of region. My issue is that I can’t seem to get my script to fire when used in conjunction with CMS load. If I for example use the infinite option, the script removes the duplicate headers for the first 100 items (I guess these are loaded with the page), but not for the following 230 items.

Is there a way to make the script trigger after CMS load has rendered the items, either using the “infinite” or “render-all” options?

Best,  
Tobias

---

<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:** [July 8, 2023, 5:52pm UTC](https://forum.finsweet.com/t/trigger-script-when-using-cms-load/1601/2 "2023-07-08T17:52:13Z")

</div>

hey @tobiastorjusen you can use the [Attributes API](https://finsweet.com/attributes/api/cms-load) to execute code when new items are rendered. Your script should look like this:

```auto
<script>
  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;

      function removeHeadings(params) {
        // Your code.
      }

      removeHeadings();

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

```

---

<div class="post-metadata">

**Author:** ![tobiastorjusen](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tobiastorjusen](https://forum.finsweet.com/u/tobiastorjusen)\
**Post date:** [July 11, 2023, 1:15pm UTC](https://forum.finsweet.com/t/trigger-script-when-using-cms-load/1601/3 "2023-07-11T13:15:15Z")

</div>

Hi,

Thanks a lot! That worked like a charm!

Best,  
Tobias
