view/frontend/templates/cookieconsent.phtml
<?php
declare(strict_types=1);
/** @var $block Staempfli\CookieConsent\Block\CookieConsent */
?>
<?php if($block->isEnabled()): ?>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
<?php echo $block->getCookieConsentConfiguration(); ?>
<?php if($block->useAdvancedConfiguration()): ?>
,
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
<?php echo $block->getChildHtml('cookie.consent.enable'); ?>
}
if (type == 'opt-out' && !didConsent) {
<?php echo $block->getChildHtml('cookie.consent.disable'); ?>
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
<?php echo $block->getChildHtml('cookie.consent.enable'); ?>
}
if (type == 'opt-out' && !didConsent) {
<?php echo $block->getChildHtml('cookie.consent.disable'); ?>
}
},
onRevokeChoice: function() {
var type = this.options.type;
if (type == 'opt-in') {
<?php echo $block->getChildHtml('cookie.consent.disable'); ?>
}
if (type == 'opt-out') {
<?php echo $block->getChildHtml('cookie.consent.enable'); ?>
}
}
<?php endif; ?>
})
});
</script>
<?php endif; ?>