Accessing child block within nested blocks


#1

I have a block within a block:

image

and I can’t figure out how to access the second block. Odd thing is that twig has no issues with it if I iterate over the first block, it finds the second block by name; however, I can’t do this from the PHP console.


#2

A dump in twig shows that it finds it:

image

I’ve since switched to a image gallery versus a block, but I need to get the data out of that block to move it into the gallery. PHP’s dump command does not have “blkMethodPhotos” in it.


#3

Try getData() function in blocks. Something like

$measurementList=$obj->getMeasurementList();
       foreach($measurementList as $measurement) {
         $blkMethodPhotos=$measurement['blkMethodPhotos']->getData();
         foreach($blkMethodPhotos as $photo) {
            ...eg: $photo['MethodPhoto']->getData();
         }
       }

#4

Yeap, this was what I needed. I was basically doing this but what I neglected to consider is that some of them are indeed null as they don’t have a value yet. I was looping through all the objects and of course the first one was this way so it threw me. Thanks.