How do I fetch an image blueprint field?

This is my blueprint:

title: Project
pages: false

fields:
    title:
        label: Title
        type: text
        
        
    projectImg:
        label: Work Image
        type: image
        icon: picture-o
        width: 1/2

I’m trying to fetch the projectImg image this way:
<img src="<?php echo $page->projectImg()->url(); ?>" alt="">
and it’s not working.

How do I correctly fetch an image type blueprint field?

Like this, always check if the image exists first before calling any method on it:

<?php
// try to get an image object
$image = $page->projectImg()->toFile();
// check if image exists
if($image): ?>
<img src="<?php echo $image->url(); ?>" alt="">
<?php endif ?>
1 Like