How to use the image select

Hello everyone,

I still have the problem to display an image by using image select. Here is my blueprint:

    label: Teaser Bild
    type: file

and my template:

<div class="row space_top5">
    <?php foreach(page('reiseangebote')->children()->limit(3) as $ang): ?>

  <img class="" src="<?= $ang->image($ang->teaser_bild())->url() ?>">

     <?php endforeach ?>

What did I wrong?

<?php if ($image = $ang->teaser_bild()->toFile()): ?>
  <img src=β€œ<?= $image->url() ?>” >
<?php endif ?>
1 Like

Thank you. What is $image ?

I have done it like and seems to work for me:

<img class="t_img img-fluid" src="<?= $ang->teaser_bild()->toFile()->url() ?>"></a>

It might work, but it is not advisable to do it like that, therefore I used the if statement above.

If you don’t check if the image exists, you will get an error if the image is removed or renamed.

The $image variable is defined in the if statement. <?php if ($image = $ang->teaser_bild()->toFile()): ?>`

It’s a shorter and better way of doing it the long way:

$image = $ang->teaser_bild()->toFile();
if ($image) {
  // stuff
1 Like