2.0.1: Cookie problem

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

2.0.1: Cookie problem

Post by pschoenb »

Hello,

since the upgrade to 2.0.1, the first line in the following code

Code: Select all

{if empty($smarty.cookies.cookie_consent)}
<!-- Begin EU cookie consent (HTML) -->

  <div id="cookie_consent">
{if $page_lang == 'de_DE'}
    <p>Wir verwenden Cookies, um Ihnen auf unserer Webseite die bestmögliche Darstellung und Seitennutzung anbieten zu können.<br />
    Wenn Sie unsere Webseite weiter nutzen, ohne Ihre Browsereinstellungen zu ändern, stimmen Sie sder Nutzung von Cookies auf dieser Webseite zu.<br />
<br />
    <a class="accept_cookies">Fortsetzen</a><a href="datenschutz" target="_blank" class="more_info">Mehr Informationen...</a></p>
{else} 
    <p>We use cookies to ensure that we give you the best experience on our website.<br />
    If you continue without changing your browser settings, we will assume that you are happy to receive all cookies on this website.<br />
    <br />
    <a class="accept_cookies">Continue</a><a href="privacy" target="_blank" class="more_info">More info...</a></p>
{/if}
  </div>

<!-- End EU cookie consent (HTML) -->
{/if}
always returns true, even though the cookie exists and is not empty.

The cookie is set as follows:

Code: Select all

{literal}
<!-- Begin EU cookie consent (JQuery) -->
<__script__ type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></__script>
<__script__ type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></__script>

<__script__ type="text/javascript">
  $(".accept_cookies").click(function () {
    $("#cookie_consent").toggle("slow");
    location.reload();
  } );

  $(document).ready(function() {
    $.cookie("cookie_consent", "yes", { domain: "klangexzellenz.de", path: "/", expires: 1095 } );
  } );
</__script>

<!--  End EU cookie consent (JQuery) -->
{/literal}
What could be wrong?
Regards,
Patrick
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

I just figured out that the problem seems to be that the overlay keeps reopening if I click "Continue". If I reload the page in the browser, though, the overlay disappears.
Regards,
Patrick
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Does anyone have a clue about what goes wrong here?
Regards,
Patrick
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: 2.0.1: Cookie problem

Post by velden »

Code: Select all

<!-- Begin olark code -->
<__script__ data-cfasync="false" type='text/javascript'>
if ( $(window).width() > 768) { 
...
Your calling above javascript BEFORE including jQuery library. Start fixing that and test again.
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

velden wrote:

Code: Select all

<!-- Begin olark code -->
<__script__ data-cfasync="false" type='text/javascript'>
if ( $(window).width() > 768) { 
...
Your calling above javascript BEFORE including jQuery library. Start fixing that and test again.
Now, I moved the JQuery stuff before any other Javascript stuff. Still the same.
Regards,
Patrick
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

For completeness: This template code worked fine with CMSMS 2.0. What could have changed?
Regards,
Patrick
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1976
Joined: Mon Jan 29, 2007 4:47 pm

Re: 2.0.1: Cookie problem

Post by Jo Morg »

pschoenb wrote:For completeness: This template code worked fine with CMSMS 2.0. What could have changed?
Difficult to say without seeing the whole template. There most likely are issues with variable scopes, but it's impossible to tell without the full template logic...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Jo Morg wrote:
pschoenb wrote:For completeness: This template code worked fine with CMSMS 2.0. What could have changed?
Difficult to say without seeing the whole template. There most likely are issues with variable scopes, but it's impossible to tell without the full template logic...
How do I check this? Could it be a problem that I wrapped all subparts into separate global conent blocks like this?

Code: Select all

{babel action="assign"}
{content block="metadescription" label="Beschreibung" oneline="true" assign="metadescription"}
{assign var='langcode' value={$lang|truncate:'2':''}}
<!DOCTYPE html>
<__html xml:lang="{$langcode}" lang="{$langcode}">
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
{SEOTools2}
{metadata}
{cms_stylesheet}
</head>

</__body>
{global_content name='Cookie Consent HTML'}

{global_content name='Cookie Consent JQuery'}

{global_content name='Google Analytics'}

<div id="wrap" class="container-fluid">
	<div id="header">
        <img src="/images/elements/banner.jpg" alt="Klangexzellenz logo"/>	</div>

    <div class="row">
        <div id="links" class="col-xs-12 col-sm-3">
            <nav class="navbar navbar-default">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" 
                        data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>

                <div class="collapse navbar-collapse">
                	<div id="babel">
                    	{babel action="menu"}
                    </div>
                    
                    <div id="avmenu">
                        {Navigator start_level="2"}
               	    </div>
                </div>
            </nav>
        </div>
        
        <div id="content" class="col-xs-12 col-sm-6">
        	{content}
        </div>

	    <div id="rechts" class="hidden-xs hidden-sm col-md-3">
	        <div id="news">
    	         {global_content name='news'}
	        </div>

       		<div id="sharing">
	            {global_content name='sharing'}
	        </div>


       <div id="social">
            {global_content name='social'}
       </div>

    		<div id="audiocation_zertifikat">
     		    {global_content name='audiocation_zertifikat'}
    		</div>
    	
    		<div id="berkleemusicmastering">
         		{global_content name='berkleemusic_mastering'}
            </div>
    		
    		<div id="drlogo">
        		{global_content name='drlogo'}
    		</div>		
    	</div>
	</div>
	
    <div id="footer">
        {global_content name='footer'}
    </div>
</div>

{global_content name='Olark'}

{global_content name='Piwik'}

{global_content name='Bootstrap'}
<__body>
</__html>
Regards,
Patrick
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Now, I've put the whole cookie consent stuff (HTML and JQuery) into a single global content block. But still, no change.

However, now I just notice that the cookie is no longer set. What could be the reason?
Regards,
Patrick
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1976
Joined: Mon Jan 29, 2007 4:47 pm

Re: 2.0.1: Cookie problem

Post by Jo Morg »

Ok, if you have put the whole code into a self-contained template (and I assume that is what you are referring to when mentioning "a single global content block" since there are no content blocks in CMSMS 2.x) one way to debug this is to compare the HTML source produced by the original site against the one produced by cloned site. There must be differences. If not then there is always the possibility that the cookie consent plugin is not working properly with CMSMS 2.x... but that is, at this point, just an assumption...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: 2.0.1: Cookie problem

Post by Rolf »

I havent upgraded a website that uses the cookie consent stuff. Will try tomorrow
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 173
Joined: Fri Feb 06, 2009 2:08 pm

Re: 2.0.1: Cookie problem

Post by PinkElephant »

pschoenb wrote:
velden wrote:

Code: Select all

if ( $(window).width() > 768) {
Your calling above javascript BEFORE including jQuery library. Start fixing that and test again.
Now, I moved the JQuery stuff before any other Javascript stuff.
Are you sure? If I'm looking in the right place, jquery is called after "$(window)" - twice, in fact - and the javascript error console shows "$ is not defined".
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: 2.0.1: Cookie problem

Post by Rolf »

I tested both methods described at http://www.cmscanbesimple.org/blog/add- ... ade-simple in a to 2.0.1.1 upgraded website.
Both work without any problem... You should have something not correct in your template or the way you implemented the tutorial
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
pschoenb
Forum Members
Forum Members
Posts: 92
Joined: Sun Jul 15, 2007 1:18 pm

Re: 2.0.1: Cookie problem

Post by pschoenb »

Ok, now, I have no JS errors anymore in the console, but still, the overlay keeps returning until I reload the page in the browser. Why?

I assume that the cookie gets set, but when the page is reloaded when clicking "Continue", the cookie is not yet present in

Code: Select all

$smarty.cookies.cookie_consent
Could that be?
Regards,
Patrick
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: 2.0.1: Cookie problem

Post by Rolf »

The cookie *is* set at your website

Try to play with

Code: Select all

{if empty($smarty.cookies.cookie_consent)}
i.e.

Code: Select all

{if !isset($smarty.cookies.cookie_consent)}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “The Lounge”