Reference

Guide

$page->image()

Returns a specific image by filename or the first one

$page->image(string $filename = null): Kirby\Cms\File|null

Parameters

Name Type Default Description
$filename string null

Return type

Kirby\Cms\File|null

Example

Fetching the first image

<?php if($image = $page->image()): ?>
<img src="<?= $image->url() ?>" alt="">
<?php endif ?>

Fetching a specific image

<?php if($image = $page->image('myimage.jpg')): ?>
<img src="<?= $image->url() ?>" alt="">
<?php endif ?>

What is an image file?

Kirby considers the following file types as images:

  • jpeg
  • jpg
  • jpe
  • gif
  • png
  • svg
  • ico
  • tif
  • tiff
  • bmp
  • psd
  • ai
  • eps
  • ps
  • webp (since v3.2.0)

Source code

kirby/src/Cms/HasFiles.php#L187