I’d like to add a picture to a page. I could upload it on my server and type in the code by myself, but I assumed Kirby could handle that as well, especially if I’d like to post something with my smartphone.
Having modified the respective blueprint, I’ve added the possibility to add a caption to my image, which is supposed to be shown if I hover on it. In addition, screenreaders for the visually impaired should read out the caption as well.
Now, if I upload an image, I expect Kirby to generate this HTML code:
When you pull an image file into the textarea field, Kirby adds an image Kirbytag. You cannot change this to markdown. If the image object has a title (i.e. in a meta file), the title is automatically added as alt attribute. So all you need to do is change the name of your field from “caption” to “title” You can also add your alt attribute manually:
(image: myimage alt: This is an amazing image)
This still won’t help you, because the p-tags are still missing. Well, I think many people here are really glad not to have the p-tags anymore, in fact, I used to use a function to remove the p-tags in Kirby 1. Is there a reason why you want p-tags around your images?
But there is a solution: Overwrite the image tag with your own syntax.
Create a new file called image.php
Save this file to /site/tags.
Copy line 60 to 158 from /kirby/extensions/tags.php and paste into your new file.
Make your changes, i.e. remove the figure stuff and replace with p tags.
Edit 2: If you are going to change the image-tag anyway, you can of course change that bit with title for alt-attribute as well and get Kirby to take use the caption field instead.
First of all, thank you very much for your help and explanations, I really appreciate it!
You’re right, I reconsidered whether it’s a good idea to wrap images around the p tag. Without it, the image would be shown in full-screen, which isn’t helpful on responsive websites. I did manage that, though, so the p tag is no longer necessary.
And changing the caption field to “title” was a great leap forward. So, basically, this is solved! Thank you!