Looking for a way to display either one image OR one video from my “news” blueprint and getting stuck. I tried a few things (below), but I’m new to kirby and not a php pro so could use some help. Thank you in advance!
You were calling the news page in your first code example, so I was assuming the files were located there.
So you are calling this code in a section snippet? Could you please provide an outline of your content structure?
To fetch a file object from a field, you can use the toFile() method:
<?php if ($file = $page->overlayimage()->toFile()): ?>
<?php if ($file->type() === 'image'): ?>
<!-- do stuff for image -->
<?php endif ?>
<?php if ($file->type() === 'video'): ?>
<!-- do stuff for video -->
<?php endif ?>
<?php endif ?>
Note that if this happens in a section snippet and you are using a different variable to refer to the page (e.g. $section) then you have to adapt the code snippet.
I have separate folders in the content folder for different areas of content on the page (ie. “news” “about” etc.) which also have separate blueprints and have been pulling content into my templates / snippets like this:
I have a header and footer snippet and home template which calls them. This particular code for the overlay image is in the header snippet.
I can give you the site url if that helps.
Tried this, but no img or video tag appears:
<?php if ($file = $page->overlayimage()->toFile()): ?>
<?php if ($file->type() === 'image'): ?>