How to make a template with nested builder and multi fieldsets?

How to make a template if there is a nested builder and there are multiple fieldsets under the second level builder?
My blueprint: (PLS notice there are multiple field sets in the nested builder)

title: manuals
icon: πŸ“

status:
  draft: true
  listed: true

fields:
  heading:
    label: Heading
    type: text
  subheading:
    label: SubHeading
    type: text
  builder:
    label: Builder
    type: builder
    fieldsets:
      cardset:
        label: Card
        fields:
          card_heading:
            label: Card Heading
            type: text
          card_content:
            label: Card Content
            type: textarea
      stepset:
        label: Step
        fields:
          stepheading:
            label: Step Heading
            type: text
          steplist:
            type: builder
            label: Step List
            columns: 2
            fieldsets:
              step:
                label: Step
                fields:
                  title:
                    label: Title
                    type: text
                  text:
                    label: Description
                    type: textarea
              steptip:
                label: Step Tip
                fields:
                  text:
                    label: Content
                    type: textarea

Template:

<?php snippet('header') ?>

<section class="uk-section">
  <div class="uk-container uk-text-center">
		<h2><?= $page->heading() ?></h2>
		<h4><?= $page->subheading()->kirbytextinline() ?></h4>	
	</div>
</section>
<?php
foreach($page->builder()->toBuilderBlocks() as $block):
  snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach;
?>

<?php snippet('footer') ?>

block stepset’s template:

<section class="uk-section">
    <div class="uk-container">
        <div class="uk-card uk-card-body">
            <h2 class="uk-card-title"><?= $data->card_heading() ?></h2>
            <p><?= $data->card_content()->kirbytext() ?></p>
        </div>
	</div>
</section>

block stepset’s template:

<section class="uk-section">
    <div class="uk-container uk-text-center">
        <h2 class="uk-card-title"><?= $data->stepheading() ?></h2>
        <ol class="uk-text-left">
<?php foreach($data->steplist()->toBuilderBlocks() as $step): ?>
            <li>
            <h4><?= $step->title()->kirbytext() ?></h4>
            <?= $step->text()->kirbytext() ?>
            </li>
<?php endforeach ?>
        </ol>
	  </div>
</section>

But I want to treat the step and step-tip units differently.

Since your nested builder field has two fieldsets, use a snippet for each set, just like for the top level builder field.

Thank you! Now my current template is modified like this.
blocks/stepset.php:

<section class="uk-section">
    <div class="uk-container uk-text-center">
        <h2 class="uk-card-title"><?= $data->stepheading() ?></h2>
<?php
foreach($data->builder()->toBuilderBlocks() as $block):
  snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach;
?>
	  </div>
</section>

blocks/step.php:

<div>
<h4><?= $dat->title() ?></h4>
<?= $data->text()->kirbytext() ?>
</div>

blocks/steptip.php:

<div>
<?= $data->text()->kirbytext() ?>
</div>

Buuut, why can not show the part of stepset?

I don’t see where you are calling the steplist builder field?

You should have

foreach ($data->steplist()->toBuilderBlocks())

in the stepset snippet.

In your blocks/step.php you have missed out an an a, should be $data not $dat.

1 Like

Awesome! You are all right!