Hello there, I still have a small question. I created a block audio that contains a mp4 file on one page like Leçons. I now try to acsess those blocks in a block Mp4 from another page. I’m sure it’s easy (but not for me), I tried to work from the code below without success. Can you help me, thank you
mp4:
type: pages
help: Audios de Espaces/ Mini-leçons depuis chez vous
empty: "Aucune leçon pour l'instant"
query: site.index.filterBy("blocks", "in", ["audio"])
Ok, then a pages field is not the right way to achieve that. For files you would need a files field. And then you need a custom method that you can use in your query.
What this custom method needs to do is find all audio blocks in a given page and of these blocks the field that contains the audio file information and convert this to a file object.
I try to do my best but din’t succeed… part is I don’t get it yet, part I have got a structure in the block I want to query
so the blocks are in the child mini-lecons of espaces
First of all, what is your blocks field called? Is it called text or something else?
Then, you need to filter by type, i.e. audio.
But then it get’s more difficulat, because the audio field is a structure field and there we get to a point where the query language doesn’t help anymore, because you have a nested structure.
Therefore, you will have to create a custom method that extracts the audio blocks and then the information you need from the structure field.
Why do you need the nested structure in the audio block instead of creating a block per audio file?
without succes, I get this error: Access to method/property filterBy on null in file: /Users/krsbee/Sites/feldenkrais/kirby/src/Toolkit/Query.php line: 242
The error means the audio.toBlocks() does not return a collection, so my assumption is that your field is not called audio, so knowing everything is vital here.
So maybe your comment means that I didn’t get the page concept right yet… this is the adress of the mini-lecons page site.test/espaces/mini-lecons. Is it that in the query kirby.page('espaces/mini-lecons') instead of espaces/mini-lecons I should pasted the name of the template of the page which is contenu.yml ? That I try without sucess. Thank you
hum… I still have two questions concerning this.
I didn’t find out how to call the nested block audio from mp4 I try foreach($block->mp4()->toBlocks() as $audio): without succes, can you point me to a solution, thank you
My second question is for the label for the mp4.yml, I try label: "{{ kirby.page('espaces/mini-lecons').contenu.toBlocks.filterBy('type', 'audio').title }}"
Many thanks