I’m building a custom popup module, when the user closes the popup I store a cookie to supress it popping up on future loads of the page.
When our content editors change something about the popup I’d like to invalidate the currently stored cookie so that the popup appears with the new content.
The way I’m doing this right now is that the popup appears when a cookie doesn’t exist. If I can get a GUID for the current module instance that changes when updates are made to the module instance, I can check if that has changed to decide if I should show the popup.
I’ve tried doing this with {{ name }} but that seems to stay the same between edits to the module instance.
Hey, @ABroadbent3 Thanks for your question. Can you share any additional details about your code with our community members? This may help in finding someone who has related experience.
What you need to do is use the content as the cookie key. This way your JS will be triggering on the key and value, assuming it’s set as a boolean.
Borrowing from @Anton 's answer, you can use the md5 filter to ensure the content is represented as a string with a predictable length when generating the key, saving you a headache or ten.
// read the cookie
if ( !readCookie({{module.property|md5}}) ) {
// Show popup
}
// set cookie
createCookie({{module.property|md5}}, true, 10)
Please don’t hesitate to reach out if you have any questions!
Finally a little unsolicited perspective:
Managing cookies via module property values is inherently not easily managed at scale. If you have access to HubDB I would recommend using it to set, change, and expire your cookie values.