Yes, first $audio is a structure item and you have to call the individual fields. Secondly, content from the files/pages/users fields is stored as yaml, so you have to use the toFile() method in this case to get the file from the content:
The if statement is necessary to make sure that the file exists before we call a method like url(). Otherwise, PHP would throw an error in case the file was renamed or deleted at a later point in time.
Wow, thank you guys for your quick responses! It is working now.
Yes, normally I use the toFile() method (i.e. with images) to get at the file object. In this case I totally forgot it, must be due to the heat here in Germany I guess
Good suggestion to use a template, Iāll try that next.
Since this is your first post here (hello! ), Iāll just assume youāre new to Kirby.
If you arenāt, you might already know thisā¦
Otherwise, this might interest you:
You can also bind data to files.
Since the presence of a structure item in your page now completely depends on the file being there, you could consider to move the data regarding the file (titel, desc), into the metadata of each file.
You would need to setup a file blueprint and change your page blueprint.
Meta data are a good way to store additional data for files. However, sometimes people donāt like the workflow for adding meta data too much, because you have to go to the file view first before you can enter the data. In that case, your structure field approach might work better. It really depends.
@rasteiner: Thanks! I read in the docs that this is possible, but I am not experienced enough (yet) to make the mental leap in order to apply it in practice. This is my first K3 project ā have used K2 for projects in the past.
Itās a good idea, but for my particular project I tend to go with with texnixeās advice ā a structure field is more āimmediateā and my client is not very computer literate. I also use a structure field on another page in the project, so thereās some sort of familiarity as far as the UX is concerned.
The question remains, what can be done about the ābroken documentā icons?
I tried to use the filename with ātext: {{ file.filename }}ā as a field option for this files field, but it doesnāt work. It is this some sort of internal referencing in the panel going wrong?
Whatās your Kirby version? I donāt get that icon but the image src uses the audio fileās url which doesnāt make sense. Strangely, setting image: false doesnāt work either. Might be a bug.
Yes, same here ā the audio fileās url is in the src of the image in the cell of the field.
Then again, when I access a row containing audio to edit it, everything displays fine (truncated screenshot):
Yes, thatās exactly the same then apart from the icon. I guess that could be solved with a custom preview for the files field in a structure field depending on mime type.
Unfortunately, setting image: false results in an error:
But maybe the issue is more the preview rather than the field itself.