Is it possible to use an image URL as a page preview in the panel?


I have a page called products. In this page there are a number of subpages which are displayed in the panel as cards, like this:

  headline: Products
  type: pages
  info: "{{ page.handle }}"
  template: shopify.product
  layout: cards
  size: small
    ratio: 16/9
    cover: true

The image query is where I’m having trouble. Ordinarily I’d just point it to the field which has the image I want, but the problem is that the fields for each product are absorbed from elsewhere using a plugin - which means the image I want to use is at the top of a structure with several image URLs, not files.

So far, I have tried using:

query: page.imageStructure.first (which results in Kirby’s default page icon for the cards - as expected, since a URL is not a file)

query: page.imageStructure.first.toFile() (which results in an error: “Argument 1 passed to Kirby\Cms\App::file() must be of the type string, array given”)
This seems odd because I thought .first would just return the URL I wanted, not an array. What am I doing wrong?
Is what I’m attempting to do even possible?

Thank you all in advance for your help.

The query expects that you return a Kirby image object, so a URL won’t do.

That’s why I thought .toFile would help. I looked around the forums a bit and people have been using .toFile in image queries with no issue. My problem is that page.imageStructure.first is returning an array rather than a string, and I’m not sure why.

You cannot convert an external file URL to a file object using toFile().
Are these URLs pointers to external files or are they URLs to actually existing files in Kirby’s folder system? If external see:

Yes, they’re external file URLs - I’ll have a look at that link, thanks for your help!
It still seems a bit complicated for something that is as easy as changing an src in templates, but it’ll have to do :slight_smile: