Is it possible to upload script via panel?

Hello!
My client has html files of interactive data graphs - the html file is basically only javascript tag inside body tag.

I wonder if can let him upload a file (only the javascript) via the panel and somehow to implement the code inside the template?

If it is possible, what kind of file do we need to create? and how can I implement it?

Thank you!

Hi,

I think the solution is very simple.

  1. You need a textarea-field in your panel for the page which should display the graph. If you want to style this field as a little code editor, this is not possible via plain-kirby but you can paste the javascript into the field and save it in the page.

  2. In your template or snippet you can then access this field and do this:
    <script><?= $page->your_field()->html() ?></script>

I think this would be a better solution then letting him upload a javascript file tbh because there would be much more to think about.

2 Likes

Hi!
thank you for the reply
Good idea - I tried this and it didn’t work - but when I removed the html() method it worked!
thanks a lot!