1

I'm a Craft beginner, so forgive me if this is an easy question.

I have an intro animation, that I'd only like to show on the first visit to the site, so that it doesn't load again when the user navigates back to the homepage after visiting other pages. Then I'd like it to expire when a user closes their browser.

I'd like to use secure cookies via the Cookies Plugin

The id of the intro animation is id="preloader"

I've put {{ setSecureCookie('intro-animation') }} above the html tag and {{ getSecureCookie('intro-animation') }} with the preloader section.

So how I do I set it up to only show the intro animation on first visit?

1

You could try something like

  {% set vidAlreadyPlayed = getSecureCookie('intro-animation') %}
        {% if not vidAlreadyPlayed %}
            {{ setSecureCookie('intro-animation', 'hey', now | date_modify("+60 seconds").timestamp ) }}
            <h1>No cookie set</h1>
            <!-- do your animation logic here -->
        {% else %}
          <!-- do something else -->
          <h1>Cookie set already</h1>
        {% endif %}
| improve this answer | |
  • No that didn't work unfortunately. But thanks for the suggestion – dave Jun 13 '18 at 10:20
  • which bit didn't work? i'm using similar code on one of my sites, just not using secure cookie (but same plugin). Have you tried just outputting some text in each if/else bit to try and see whats happening? – alexr Jun 13 '18 at 10:26
  • I changed it to just text only and not a secure cookie as well to see if that was the issue, but it still just shows the same text each time – dave Jun 13 '18 at 10:36
  • is it finding the cookie? e.g. is it defaulting to whats in the if or whats in the else? – alexr Jun 13 '18 at 10:45
  • It's showing whats in the if. i.e. I've just set it to say hello. So am seeing that only – dave Jun 13 '18 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.