Dawn theme: How to handle secion and block JavaScript events

Dawn theme: How to handle secion and block JavaScript events

tobychen
Shopify Partner
10 0 4

Hi,

 

Could someone give me instructions on how to handle section and block JavaScript events on Dawn theme?

For example, Shopify emits JavaScript events such as shopify:section:select, shopify:block:select, etc. I want to know how to handle these events on specific elements such as MenuDrawer and HeaderDrawer in performace-optimized ways.

 

Thanks.

Reply 1 (1)

Ludovic_Segura
Shopify Staff
1 0 1

Hey there @tobychen ,

 

In order to do something when a section is re rendered or a block selected/deselected, you would use those events: https://shopify.dev/themes/architecture/sections/integrate-sections-with-the-theme-editor#section-an...

 

So for example you could set an event listener on the document to listen for the event: `shopify:section:load`. And in your function to deal with the event, you can log the `event.detail` and it will give you the information mentioned in the table from the link I shared above. So for shopify:section:load it will give you the section ID of the section that is being re rendered. 

Does that help ?

To learn more visit the Shopify Help Center or the Community Blog.