Content from Database in Panel with local files

Hi

I have a Database with several columns. One of the column has a reference to an image (e.g. c3f7d6a95fe3d55bf4d41a53a99933b9.jpg)
The files are downloaded & imported using a different script and exist within kirby [located in /content/c3f7d6a95fe3d55bf4d41a53a99933b9.jpg using site()->createFile()]

Using the content from a database guide, I created the model and can access the database content, but I can’t seem to manage to add those files to the page?

I’ve seen that there is an option of 'files' for the Pages::factory, but I could not figure out how to add files?

Or am I overlooking some obvious documentation?

Any help is appreciated!
Best
Gork

If your files are stored in the site object, they are not part of the current page. So you need a reference to your file (the filename) in the content in some field of your choice, then in your template you can fetch it by filename from the site object.

Heya Sonja!

Thanks for your quick reply!

How can I reference this in the field? I want it to be shown (linked?) within the panel, also to use it as preview image for the site etc?
Or: how can I make it part of the current page? Without having to create the page within the filesystem (or using mixed mode) and keeping everything within the database?

Showing it in the frontend / template is solved

In your model, you could just add the filename in some field

'content' => [
  'myFile' => 'c3f7d6a95fe3d55bf4d41a53a99933b9.jpg',
  // rest of content array
];

Then in your template

<?php if ($file = $site->files()->find($page->myFile()->value())) {
  echo $file;
}

Hi Sonja!

But this will not show me the image in the panel, will it?
Can’t use it for a preview image?

Well, you can fetch it with a query: page.myFile.toFile()

wooow!
I somehow was under the impression I had to pass a files object or something!
But just a filename worked!
Amazing!!

Much much easier and I overcomplicated things!