I am planning to use Kirby for some sort of blog style website, so in the panel I plan on using something like the editor or the new blocks feature. This will work fine for regular content like text, images or even tables.
However, on the site in question, every once in a while, I need to include some sort of custom coded interactive things that require a more complex coding setup (probably some dedicated HTML / CSS / JS files, including some dedicated media files). A good example for that would be some sort of interactive map, maybe like in this example here. However, these could be very different examples, so they don’t always follow the same structure.
Now I wonder: How can I include things like that into a blog article via the panel? Is there maybe any way to point Kirby to a folder and then let it load this folder into an iframe or something like that? Looking for ideas!
Thanks!
Edit: Replaced all the "backend"s with "panel"s, because that’s what I actually meant.
Sorry, I realize I was not quite clear enough on the backend part, my mistake:
I would like to be able to somehow tie in these “blocks” with the panel (that’s what I meant by backend in my original post). As far as I know, snippets are not really connected to the panel, so they would probably not help me much in this case, right?
Could you elaborate? Is this something that needs to be custom written? Or can this be done with Kirby’s onboard tools?
Maybe to elaborate a bit more: I will need this in the panel, because I will need the editors to be able to somehow pick one of these blocks and have them decide where to place that within the article. If there are any other mechanisms for that that come to mine, I’m open for ideas.
With the new Kirby block, it should be possible to define a select field that is fed with options through a route. This route could return possible snippets from a specific folder that are then retrieved within the block snippet.
So this means writing a new custom select field for snippets, right?
I am afraid this is way above my skill level.
Are there any other ways/ideas? Would there maybe be a way to define a simple field that contains a simple link to some subfolder (outside the content folder) that would allow me to pull in this subfolder’s contents?
No, in the new blocks field, you can add a fieldset with a select field. Within this select field, you can use all queries (from other field, from API etc.) that you can use in a select field as set out in the documentation. So you would probably use an API query and your API would be a route that returns a list of snippets in a folder.
Woah, ok, I had no idea that select fields can be used in that way. This sounds like a good option. I will give this a try and see if I can get this to work. Thanks!
Ok, I am just trying to make sense of this, but I don’t know what I have to do.
In the blueprint, for the select field, I guess I have to use the api option:
But what do I have to put into the URL property? How do I actually connect this to the snippets? Do I have to create some API endpoint for the snippets first? If so, how can I do this? Sorry, first time I try to use the Kirby API feature and I am lost.
Hm, I think I understand the setup of the select field, as I was able to create a test setup with an external API and managed to load a JSON as a list into this field.
However, I am still having trouble to set up the routing. If my pattern parameter is
pattern: 'my-api/snippets.json'
how do I set up the return statement so that it points at my snippets folder (or any other non-content folder for that matter)? Could anyone give me a brief example?
While this does work, the page that appears in the iframe gets overwritten by Kirby’s default template. So I don’t actually get the html page that I want in my iframe, but the default page. Is there a way to skip the applying of this default template?
I don’t quite understand how Kirby handles the applying of templates to iframe-embedded pages, but I would like it to apply no template whatsoever in this case.
A snippet doesn’t have a URL,only a path. But for an iframe, you need a URL. I would have expected that you render the snippet directly in your template, not inside an iframe. Or if it is an iframe, that the iframe is in the snippet.
Ah, that makes sense. Now I also understand why it should be handled via snippets and not any other arbitrary folder.
However, I am trying to get this to work, when I include the iframe in the snippet itself (or wrap it around the snippet() method in my template) it kind of pulls it into the document, but it seems to handle the html code as some sort of string instead of html? Any idea how to avoid this and make it render as actual html within the iframe?
This may be irrelevant now, but I had to do something similar and was able to paste some complex iframe code into the blocks > markdown field, that then rendered as an iframe in the frontend.