Thanks to Paul Massendari for helping me figure this out in the Slack group!
His suggestion below:
Philippe Levy [9:49 AM]
Hey Paul. I read all of your threads about putting page specific js snippets in the <head></head> block on modular pages and I was hoping I could ask you some questions about it. I'm beating myself up trying to figure this out!
paul_massendari [11:43 AM]
hi Philippe, sure, ask away!
Philippe Levy [11:56 AM]
Awesome. The js snippet the asset manager is loading appears to be pipelined and placed below the footer when I look at page source instead of in the head. The code snippets I'm trying to place are just page specific Google Tag Manager snippets that are supposed to be placed in the <head> and only fire on that page alone. The only way I have been able to figure out how to do this is to put all these snippets in base.html.twig <head> with twig if statements with page.title conditions. There will be many of them, so doesn't seem like a clean way to do it! What do you recommend?
paul_massendari [11:58 AM]
hmm I would not be worried about the multiple if statement. Keep in mind it takes only a few milisecond to process all of it
in this theme I rely on it a lot just for icons: https://github.com/paulmassen/grav-theme-chalk/blob/master/templates/partials/footer.html.twig
GitHub
paulmassen/grav-theme-chalk
grav-theme-chalk - Port of the Jekyll's chalk theme to Grav CMS
are your snippet page specific or template specific?
Philippe Levy [12:00 PM]
I pasted the snippets in their entirety for each if but you're saying the code snippets are only processed if the if condition is met?
paul_massendari [12:01 PM]
yes, sure
The snippet wont appear in your page source if you write it inside if statement
and the condition is not met
Philippe Levy [12:02 PM]
Ahh cool. Merci mon homme!
paul_massendari [12:03 PM]
ah au ! de rien!