I'm looking to create a custom module which launches a pop up video. However, I can only have one instance per web page, i've tried to use {% require_css %} & {%require_js%} to load the css and js in header and footer.
I'm first and foremost a marketer so struggling slight, any help is appreaciated.
Their are a couple ways you could go about this, the way that is technically not quite optimized but definitely the easiest from your current state is to add #{{ name }} before every reference to a class or id in your javascript. It's breaking from multiple instances because you shouldn't have multiple items with the same ID on the same page.
If I were you I would update the IDs to be classes instead, or wherever you are setting an id, add -{{name}} after it so that the IDs are unique for each instance of the module.
Their are a couple ways you could go about this, the way that is technically not quite optimized but definitely the easiest from your current state is to add #{{ name }} before every reference to a class or id in your javascript. It's breaking from multiple instances because you shouldn't have multiple items with the same ID on the same page.
If I were you I would update the IDs to be classes instead, or wherever you are setting an id, add -{{name}} after it so that the IDs are unique for each instance of the module.
I would recommend to seperate the CSS part from the module and just "link" it.
To do so:
create a new CSS file in your theme, copy-paste everything between <style> and </style> into it and save it as "myModule.css"(give it a certain name). After that open your module and select it in the right sidebar in the "linked files" option.
Or paste the CSS code into your main CSS file if you never change those stylings and use the module quite often.
Same goes for JS. This works with both files unless you're modifing it via hubl.