Using the Image Type in a Structure

I am using an image type inside a structure in my blueprint like below. Everything works fine when I am in the panel, but I am not sure how to access the image or image url.

  Cars:
    label: Cars
    type: structure
    style: table
    entry: >
      {{name}}
      {{details}}
      {{picture}}
    fields:
      name:
        label: Name
        type: text
      details:
        label: Details
        type: textarea
      picture:
        label: Vehicle Image
        type: image

When I call the below code it only gives me the image name. I’ve tried using url() but it only gives http://domain.com/image.jpg and not the actual url to the image.

<?php echo $car->picture()->image() ?>

1 Like

Replace image() by toFile() - >url()

1 Like

The image field saves the name of the image. So to fetch the image in your templates your have to pass the value of the field to the image method like this:

<?php echo $page->image($car->picture()) ?>
1 Like

This worked for me.

<?php echo $car->picture()->toFile() ?>

1 Like

Sorry for my super short answer, I was writing from my phone :slight_smile:

We’re writing a tutorial for next week on Structures at @macotuts. Using images inside the field will definitely be a part of it as it’s an often encountered need!

Glad you found your answer.

Math

1 Like