I’m currently building a website and am using the Kirby Builder plugin to create modules which I can setup within the panel, this is now all working really nicely (blueprint below), however I’m struggling to get the images from the gallery module(s) to display on the page.
Here is the blueprint which defines the gallery module:
Within the gallery snippet / block I’ve tried various things to try and get the images to display however I’m not having any luck - Can someone advise on how to go about accessing and outputting the images? Here is what I have so far:
Wow, thank was quick and working perfectly, thank you Texnixe .
Just so I can learn and figure out where $data comes from, is that defined within the array in the template? I presume $data stores the input from the fields so I then use $data to access all of the modules and their contents? Any explanation of what this doing would be so helpful:
Here you store the $block variable in $data in the snippet. I personally don’t know if this is such a happy decision and would myself use the $block variable inside the snippets and therefore store $block in block:
but that is completely up to you, you can freely define what variable you want to use inside the snippet. data is not set in stone. However, if you copy stuff from examples, you have to keep in mind that these examples might use different variables.
In any case, inside the snippet, the variable you use refers to an individual block, which has a set of fields that you can call by $data->fieldname()- do not call the main builder field again inside your snippet.
On a side note: If your block contains a nested builder field, you would then have to call the toBuilderBlocks() method again on that field inside the snippet-
Understood, that makes perfect sense - Many thanks for taking the time to help me understand, I would have never of figured that out and agreed $block would make more sense over $data so I’ll update that now.
Noted re: nested fields, will remember that moving forward!
This works the same way for all snippets, not only the ones used for the builder blocks. And you can of course pass more variables to snippets if needed