I’m creating a website for a client and i would like he could insert the image caption in the image preview.
i know how to recover the metadata info if i create the code, but the function $page->text()->kirbytext() recover all the information in the text box from the panel by itself.
There is any way to tell the template if the image has the metadata filled include the content in the page?
PD. I know user can insert caption this way (image: crafting-type-sg_06-600x260.jpg caption: ‘bla’), but i prefer the panel option if it’s possible.
I don’t know if I understood that correctly, but does this code help?
<?php $image = $page->image('myimage.jpg'); ?>
<?php if($caption = $image->meta()->caption()): ?>
This image has the caption <?php echo $caption ?>
<?php endif ?>
Not exactly. The way you propose is perfect if I insert the code to include images. My problem is that all the contents (paragraphs, images, list,…) are inserted by the $page->text()->kirbytext() function. So i don’t know how to include extra code to this function.
And i don’t know how to include the elements in order if i don’t use this function. I mean sometimes images are between paragraphs. If i include all the paragraphs and then all the images they are going to be disorded.
have i explained myself?
Thank you for your help!
You could create a custom image tag (copy the existing one to overwrite it) that get’s the caption from the image meta data.
The procedure is similar to the one described in this post, with the difference that you don’t want to create thumbnails but add captions.
I’ve got it!! ^^
Thank you texnixe!!
I should be careful updating kirby from now, doesn’t it?
There’s always a risk that something breaks if you update, but as long as you copied the tag into /site/tags and did not change the source code, you are fairly safe.
mmm, actually i did change it in the source code Thank you for the warning advise!
Well, then your changes will get overwritten as soon as you update. All you need to do, is copy the image tag bit into a separate file and save it as image.php in /site/tags.
Fixed! Thank you very much again!