Can we add JS snippets to panel field, not to hack the panel, but to add google analytics, mixpanel, etc. from panel then access from templates (?)
Have a look here.
Thank you. Not what I’m asking for.
Of course you can add a normal text field in your site´s settings (
site.php blueprint), write code into it and access this field, as any other, from your template. If you don´t parse this as kirbytext, the content should be the same.
Anyway, I think, if would be a much cleaner solution to add code for all templates in a snippet (e.g. header / footer / scripts before end) and set the tracking ID in the
config.php (so you can disable analytics on your localhost development environment easily, if you use this) or in your site´s settings, so everyone can edit them.
For an example, see this solution: https://getkirby.com/docs/solutions/piwik
- Some scripts (like mixpanel’s) are unique in every case (no generic formula here)
- I want to let the user customize the snippet as needed
- I don’t want to hard-code it into the template
I thought a panel field would be great alternative this time.
Actually I’m exploring panel fields as an alternative to that.
But you’re right in general, thank you.
I had no problem adding this:
or even just the pure script (without the html
I used a standard
textarea panel field and got the text to my website even with
@jbeyerstedt is right, adding script to a field is no problem.
- It works seamlessly
On test server:
- When I put JS into the field and hit “save”, it keeps loading and loading, but it never resolves
- It saves HTML/CSS with no problem (but I don’t need those)
- It’s the same for textarea and custom field type, so I guess my custom field was not the problem
My panel field:
(This error is only thrown if I put JS into the panel field)
404 (Not Found) panel.min.js?v=2.2.3:5 V.cors.t.crossDomain.send @ panel.min.js?v=2.2.3:5 K.extend.ajax @ panel.min.js?v=2.2.3:5 K.(anonymous function) @ panel.min.js?v=2.2.3:5 (anonymous function) @ panel.min.js?v=2.2.3:7 K.event.dispatch @ panel.min.js?v=2.2.3:4 g.handle @ panel.min.js?v=2.2.3:4
That´s interesting. I tested it on my web server (uberspace.de, CentOS) as well, and it was no problem.
My next step to isolate the problem would be, to install a new starter kit and try saving this text in there. Could you try this?
Or do you have solved this problem (because this thread is marked as solved)?
No, I marked that as “solved”, because I think it should work. Also tested this on my remote server without problems.
I wonder if the issue is server specific somehow, not allowing to post scripts.
- localhost: It works anyway all the time
- remote server: it works from content pages, but not from site options page
So yes, textarea accepts JS, but not from site options
Maybe the server is not the problem
Maybe I messed up site options, but don’t know where (?)
I will test with a new installation