I followed this cookbook on Virtual files to fetch images via API into Kirby.
To use this on different pages with different API calls for different file sources (but from the same API), I need to adjust the URL of the call.
I am ending with duplicating the file model for each page but maybe there is a better, more flexible way?!
Thank you all!
You probably mean the page model, not the file model? You definitely need a page model for every page if the pages use different blueprints, but you could create a basePage model that your page models extend.
You can also use the same page model for all pages if you register them in a plugin (see last section in this recipe):
Then you only need to get the API call for each page from somewhere, maybe create an array of API endpoints in the plugin options, then fetch by page intended template.
Thank you, @texnixe. Oh, yes, I ment page model. Thanks for the Quicktipp hint, that helps a lot!
Good Morning @texnixe,
when I try to delete a page with my page model, I get an error:
Error: Return value of CdnFile::delete() must be of the type bool, none returned
The file class is called CdnFile but is just a copy from the cookbook example: Virtual files | Kirby CMS
I have two page models for two different api calls and the error is just happeing when I delete pages with one of the models. The difference is the api request.
Do you have a hint for me, what is happenig here?
What does your
delete() method look like? As the error message says, it has to return a boolean, maybe you didn’t add a body to the method?
It’s from the cookbook example and empty, but for the file. Don‘t see anything for the page.
public function delete(bool $force = false): bool
// code to delete file
It shouldn’t be empty, it has to return a boolean value. So this method should simply return true, since you don’t have to do anything to delete the file, I guess.
When you delete a page, the files that belong to a page must also be deleted.
Okay, thak you! I was wondering why it didn’t show an error with the other page model using the same file model now it is working with all pages.