Developer forum

Forum » CMS - Standard features » Add option to change Cookie setings

Add option to change Cookie setings

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have been asked by an SEO company to add an option to access cookie consent with the ability to change the previously set consent.

Something similar with the behavior of this page: https://cookieinformation.com/ (see the bottom left corner after accepting the cookies)

I know that the Cookie activation is set in the back-end and loaded server-side when the page loads and there is no cookie consent at all.

Is there any way I can trigger the cookie banner again even if I have a value for CookieOptInLevel? 

Thank you,
Adrian


Replies

 
Suzi Louring
Suzi Louring
Reply

+1

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

Untested:

In the end of the master template, just before body end, insert this:

   @{
        if(Dynamicweb.Context.Current.Request.QueryString["showcookiebanner"].Equals("true", StringComparison.OrdinalIgnoreCase))
        {
            @RenderPartial($"CookieWarning/{Pageview.Area.CookieWarningTemplate}")
        }
    }

</body>

Then in the Cookies.chtml template make this change in the top, adding "optInCategories"

 var categories = CookieManager.GetCategories();
 var optInCategories = CookieManager.GetCookieOptInCategories();

And then furhter down add a checked attribute to the checkboxes:

<input class="form-check-input js-checkbox" type="checkbox" checked="@optInCategories.Contains(category)" ...:>

After this change, you can link to any page using ?showcookiebanner=true in the URL which will pop the cookie notice with the selection the user has already made.

 

You must be logged in to post in the forum