Nested fields from page builder

Hello everyone,

I am using the kirby 3 page builder plugin. I struggle to call a nested field from the page builder.
I found a related topic and copied the code and adjusted it to my needs. But it won’t do anything and I get empty divs. I want to get the images and in the next step I want to call for the other infos as well (personname, persontask, etc).

<div>
  <?php foreach($data->teamlist()->toBuilderBlocks() as $subBlock): ?>
    <?php if($file = $subBlock->teamimages()->toFile()): ?>
      <figure>
      <img src="<?= $file->url() ?>" alt="">
      </figure>
    <?php endif ?>
  <?php endforeach ?>
</div>

How the pagebuilder is called:

<?php
  foreach($page->mybuilder()->toBuilderBlocks() as $block) {
    snippet('blocks/' . $block->_key(), array('data' => $block));
  };
  ?>

This is my blueprint:

type: builder
label: Teams
fields:
  title:
    label: Team Saison XY
    type: text
    width: 1/4
  selectclass:
    label: Team dem Archiv hinzufügen
    help: Checkbox markieren, um Team zum Archiv hinzuzufügen
    type: checkboxes
    width: 1/4
    options:
      archive: archivieren
  teamlist:
    label: Teamliste
    type: builder
    fieldsets:
      group:
        label: Gruppe
        fields:
          grouptask:
            label: Aufgabenbereich
            type: text
          teammember:
            label: Mitgliederliste
            type: builder
            fieldsets:
              member:
                label: Mitglied
                fields:
                  teamimages:
                    label: Portait
                    type: files
                    width: 1/4
                    multiple: false
                  personname:
                    label: Name
                    type: text
                    width: 1/4
                  persontask:
                    label: Aufgabenbereich
                    type: text
                    width: 1/4
                  personmail:
                    label: Emailadresse
                    type: link
                    width: 1/4
                    options:
                      - email

Extract of my contenpage (maybe this also helps):

teamlist:
    - 
      grouptask: Aufgabenbereich
      teammember:
        - 
          teamimages:
            - logo-0025-melasta.png
          personname: Vanessa Schadenberg
          persontask: Aufgabe
          personmail:
            link: hallo@vanessaschadenberg.com
            type: email
          _key: member
          _uid: member_1560542698782_287
      _key: group
      _uid: group_1560542697680_217
    - 

I really would appreciate the help!

Somehow there’s something missing from your blueprint, because for the first level, there’s not fields defined.

Anyway, in the snippet for this first fieldset, your code should look something like this:

<section class="fieldset1">
 
    <?= $data->title() ?>
    <?php foreach ($data->teamlist()->toBuilderBlocks() as $subblock):  ?>
        <?php foreach ($subblock->teammember()->toBuilderBlocks() as $teammember): ?>
            <?= $teammember->personname() ?>
            <?= $teammember->persontask() ?>
            <?php if ($image = $teammember->teamimages()->toFile()): ?>
              <img src="<?= $image->url() ?>">
            <?php endif ?>
        <?php endforeach ?>
    <?php endforeach ?>
</section>

Don’t know why you are using the builder field here, because a native structure would do the job, unless you area using different fieldsets that are not shown here.

1 Like

Hi, thank you very much for your help! That code of yours works pretty fine and it looks so easy the way you did it. PHP is still something new to me, but I try my best to learn and understand it. This kirby project is my very first and I do this for my university team.

Don’t know why you are using the builder field here, because a native structure would do the job, unless you area using different fieldsets that are not shown here.

So the team changes every 2 semesters, but we want to keep the old teams in the “team archive” on the website. That is why I created this structure:

  • I wanted to create a new block for every team (a team lasts 2 semesters).
  • In a team there are different groups that are responsible for different tasks.
  • Each group has a bunch of members. Each member should be shown with a portrait (used a placeholder image here), name and emailaddress.

I also have other fieldsets on the same level as “teams” like a text section, blockquotes, image slider and so on that I can place in my Page Builder. That is why I created “teams” as a builder block, so I can place and change positions of every block.

Thanks again for your great help, very appreciated! :slight_smile: