I need help, please I am trying to fetch for an image from the children page. It shows a broken image icon on the page when I view it. Can someone share with me what I am doing wrong?
<?php foreach($page->children()->visible() as $subpage):?>
<?php if($image = $subpage->coverImage()->first()): ?>
<img src="<?php echo $image->url(); ?>" />
<?php endif ?>
<?php endforeach ?>
Is coverImage
a field? What does it contain?
You can fetch the first of all images like this:
$image = $subpage->images()->first();
But not coverage()->first()
Removed the coverImage field and fetched the image first; works.
But now the images are not showing up on the main page only subpage.
I donβt quite understand. Please provide some more context. In which template did you put that code? What do you want to fetch?
1 Like
Have you sorted this out now? You deleted your answerβ¦
I was able to get the image to display on the page. I am having other issues which, require me to learn more about Kirby cms. I am sure this a dumb question, how can you write clean else statement in Kirby?
What do you mean with clean else statement?
<?php
$a = 'hello';
$b = 'hallo';
if($a === $b) {
echo "a is the same as b";
} else {
echo "a is different from b";
}
I know that it is sometimes very difficult to ask the right questions if you are not very familiar with a topic. But please try to be more specific and give examples or post some code or tell us what you are trying to achieve. Otherwise trying to give the right answer is more guesswork than anything else.