elleracompany / craft-cookie-consent

GDPR-Compliant cookie consent banner for Craft CMS
Other
6 stars 5 forks source link

Cookie Consent is not working on 404 Pages #55

Closed wizzywiggs closed 4 months ago

wizzywiggs commented 3 years ago

If you go to /404 page (by default Craft uses 404.twig) the cookie works but if you end up on any non-existent uncpecific (404) pages on your site, the div container for cookies show up but none of javascript or css are getting added. I think it has something to do with the {% hook 'before-body-end' %} generating those js and css dynamically.

I also tried moving hook in another component and forcing my template to use existing entry. Nothing. This seems to be not working with anything that does not exist as far as entry. Please let me know how this can be fixed. I am running out of ideas

peteralewis commented 3 years ago

Have you tried copying (and renaming) the style.css & script.js from here: vendor/elleracompany/craft-cookie-consent/src/resources to your asset folder and including manually in the 404 template?

{% js "/assets/js/cookie-consent.min.js" %}
{% css "/assets/css/cookie-consent.css" %}

...?

wizzywiggs commented 3 years ago

Have you tried copying (and renaming) the style.css & script.js from here: vendor/elleracompany/craft-cookie-consent/src/resources to your asset folder and including manually in the 404 template?

{% js "/assets/js/cookie-consent.min.js" %}
{% css "/assets/css/cookie-consent.css" %}

...?

I have thought about doing something like this, it might be worth a try! Thanks! I'll post and update if this works.

jellingsen commented 3 years ago

The CSS and JS files are injected with Craft::$app->view->registerAssetBundle() and are not tied to the template or the hook.

There might be some runtime condition that breaks out for those 404s before the plugin is initialized. I will need to investigate this further, but as a temporary solution @peteralewis suggestion should do the trick (if you include those lines in a global layout file, you should disable the loading of assets in the site settings, "Load CSS Assets" and "Load JS Assets").

jellingsen commented 3 years ago

@wizzywiggs - did you get it to work?

wizzywiggs commented 3 years ago

Yes, I did. Do you want me to send you the sample of that template? I would be happy to show it

On Sat, Feb 6, 2021 at 04:27 jellingsen notifications@github.com wrote:

@wizzywiggs https://github.com/wizzywiggs - did you get it to work?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/elleracompany/craft-cookie-consent/issues/55#issuecomment-774443012, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUI3MN5CDEMCJLUJKGGQ73S5UKQBANCNFSM4T2OOLTA .

-- [image: Shift Interactive]

Roman Serebryakov UX Designer roman.serebryakov@shiftdsm.com

1501 42nd Street #580 West Des Moines, IA 50266 https://www.google.com/maps/place/1501+42nd+St+%23550,+West+Des+Moines,+IA+50266/@41.593189,-93.760198,17z/data=!3m1!4b1!4m2!3m1!1s0x87ec2093bed36c19:0xaa9e8e2834cde0d shiftdsm.com

An Anthologic Company

mikewink commented 1 year ago

I'm running into the same problem on Craft 4. Has this issue been worked on, or what is/was the solution @wizzywiggs? Thank you for any tip. :)