How to add a "Code injection" area in the panel?

In Ghost CMS there is the possibility to add specific code to the header or footer of the current page/article like this:


Is there the possibility to add this feature to the Kirby panel as well?

Letting users inject code is always a risk.

Custom styles are certainly no problem. Script tags can be added through a textarea field as well, but I’d be careful.

What exactly is your use case?

Alternatives would be to give users some options of scripts they can select and then load these conditionally.

I am the only user of my blog and want to have the possibility to embed things like Flickr photostream with light box gallery or add a timeline.js add on to a page for example without always creating a specific snippet only for one case.

Well, you can add script tags in a textarea field, for example.

I’m not 100% sure that formatting JavaScript works properly, I think there were some issues with identation etc., but you can just test if it works as expected.

I tried it with this code but it didn’t work:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<link href="//cdn.rawgit.com/noelboss/featherlight/1.7.13/release/featherlight.min.css" type="text/css" rel="stylesheet" />
<link href="//cdn.rawgit.com/noelboss/featherlight/1.7.13/release/featherlight.gallery.min.css" type="text/css" rel="stylesheet" />
<style>
.post-body a {
    box-shadow: none !important;
}
.post-body a:hover {
    box-shadow: none !important;
}
.post-inner a:not(.kg-bookmark-container):not(.button){
    border-bottom: 0px !important;
}
</style>

How do you render the field in your template?

With Markdown

What does that mean?

Assuming you have a textarea field in your blueprint called textarea, you can render it with

<?= $page->textarea() ?>

And the script/style tags should appear in the frontend source code

Thanks, it worked :slight_smile: