Hi there,
Using the Kirby-builder, I’m having trouble figuring out how to access values in a nested snippet from a level up within an array structure.
My file structure looks like this:
blueprints/fields/builder/contentblock.yml
blueprints/fields/builder/nested/textblock.yml
snippets/builder/contentblock.php
snippets/builder/nested/textblock.php
I want to be able to define some variables once in contentblock.yml and use them inside the textblock.php snippet in a foreach loop.
My blueprint structure looks something like this:
label: Content Block
fields:
builder_nested:
label: Content body
type: builder
fieldsets:
button:
extends: fields/builder/nested/button
copy:
extends: fields/builder/nested/textblock
sectionbghex:
label: Section BG colour
type: text
copy_hex:
label: Section Text Hex
type: text
The foreach loop in contentblock.php works fine:
<?php foreach($data->builder_nested()->toBuilderBlocks() as $block): ?>
<?php snippet('builder/nested/' . $block->_key(), array('data' => $block)) ?>
<?php endforeach ?>
Inside textblock.php, I can access the nested values under builder_nested
, but not sectionbghex
nor copy_hex
I’ve tried passing a variable into the snippet like this:
<?php snippet('builder/nested/' . $block->_key(), array('data' => $block), array('copy_hex' => $data->copy_hex())) ?>
but this throws an error:
Argument 3 passed to snippet() must be of the type boolean, array given, called in …/site/snippets/builder/contentblock.php on line 16
I‘m a relative newb to this and most of my php & Kirby knowledge has been carved out by trial and error, so it could well be that this is a really basic principle that I’ve missed – sorry about that