Heya!
I was overwriting the template eu_cookie_compliance_popup_info.html.twig from within my custom theme, when I realised that adding a library in the file, didn't do anything.
So I went to investigate and realised that when using eu_cookie_compliance module, and having template suggestions turned on, you can't actually discover the template as a frontend developer.
I had a peek in to the module's code and would suggest that we do an actual ->render() by rewriting the hook_page_attachments in to a hook_page_preprocess.
I wrote a patch to show what I mean, and it looks like it's working: when I now overwrite the template the added library is included too + the theme_suggestions are now visible when rendering the page!
Let me know what you think! Patch incoming :)
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | eu_cookie_compliance-render-the-templates-of-the-module-in-a-better-way-2974324-28.patch | 15.54 KB | svenryen |
Comments
Comment #2
mathieuspil commentedComment #3
svenryen commentedThanks for the patch. I don't think this change will make it into the next version (GDPR issues, currently overdue), and the patch may need a re-roll to also include the mobile banner and then "withdraw consent" banner that are about to be added to the -dev branch.
Comment #4
svenryen commentedDoes this actually work? You're rendering either the html_info version OR the html_agreed version and then including them in the javascript settings array. Correct me if I'm wrong, but normally we would need both rendered, since the user may see the Thank you message after he has dismissed the first (info) message.
See above.
I haven't looked into the rest of the patch in detail, so there may be more issues. It would also be nice if when you think the code requires cleanup, you can open a separate issue on that, so there's less "noise" in the proposed patch.
Comment #5
svenryen commentedAlso, code style: For drupal modules there should be a space between "if" and the opening parentheses.
Comment #6
mathieuspil commentedaha, in my current project, we are not using the popup_agreed_enabled option, so its likely your tought of #3 would make the first patch wrong indeed.
Cleaned up a bit, so it has less meaningless lines, sorry about that :)
Comment #7
svenryen commentedThanks, looks better now (though haven't tested it). It still will need a re-roll in a couple of days.
Comment #8
svenryen commentedComment #10
svenryen commentedThe patch failed to apply. Can you check out the current -dev and update the patch?
Comment #11
mathieuspil commentedUpdated the patch to reflect the latest dev version!
This went off my radar for a bit too long :)
Same things, but now doing it for multiple templates within the .module file
And now without messing with indentation in the template files
Comment #12
svenryen commentedComment #13
nitebreedRe-rolled the patch against the latest dev
Comment #15
svenryen commentedComment #16
aaronmchalePatch in #13 seems to work for me, before applying the patch template files in my theme weren't being used and no theme hook suggestions were being displayed when Twig debug mode was on, now template from my theme is used and theme hook suggestions show.
Comment #17
abaier commentedI can verify that patch #13 lets the template suggestions show up. But to mention is, that I was also able to override the original templates before, by copying them to my theme. I did not try to include a library though.
Unfortunately I get the following warning/notice after applying the patch:
Comment #18
a.dmitriiev commentedRe-rolled patch for version 1.5. I also fixed some coding standards and added missing variables to desktop template.
Comment #19
svenryen commentedThanks for the re-roll. I'll try to look at this patch soon to get this fixed.
Comment #20
svenryen commentedThanks again for the patch, @a.dmitriiev.
Comments:
Is there any reason why we're dropping cache tags from the changed file?
I think use statements are preferred to including the paths in code. (This code has been changed in the -dev branch, so it doesn't really matter that much any more.)
Comment #21
a.dmitriiev commentedI think there is no reason to remove the cache tags, sorry, I've not seen that. It was kind of silly re-roll. Of course, they should stay.
Comment #22
majid.ali commentedRe-rolled patch for version 1.8. As discussed in #20 and #21 i did not removed the cache tags and kept the use statements for including path.
Comment #23
majid.ali commentedComment #24
driskell commentedI tried to re-roll this onto 1.9 looks to be applying.
Comment #25
driskell commentedSomehow the patch was broken. Trying this one.
Comment #26
driskell commentedComment #27
brendan.smith commentedTested the patch in Comment #25 with v1.9 of the module and v8.8.6 of Drupal Core.
It fixed an issue we had where the template eu_cookie_compliance_popup_info.html.twig was not being overridden in a Base Theme that we inherit in sub-themes.
Comment #28
svenryen commentedI rerolled the patch and it seems to work well.
Comment #30
svenryen commented