But I cant really get my head around on how to do the same thing for the files. Adding the following ends up in an error message “Call to a member function file() on array”.
Thanks for the reply!
Unfortunately I still can’t make it work.
When using the yaml code you’ve posted, I’m prompted with the following error:
Argument 1 passed to Kirby\Cms\Page::file() must be of the type string or null, array given, called in /Applications/MAMP/htdocs/cmlab-kirby/site/templates/event_simple.php on line 76
Hm, weird. Using your code and switching to toStructure() resolves the error message but doesn’t show any file links. It seems like the if statement simply never executes.
I can’t see why the code should not do what it is supposed to to. Unless you have more than one file per files field, in which case we would have to change from toFile() to toFiles() and use another loop. But from what I understood, there is only one file per structure item?
Ouch, my bad. I only added a file name to the field in the content file but didn’t add the actual file in the folder. That’s why nothing was showing up.