How to show builder nested fieldset in template?

I am trying to make nested fieldsets. Template files are in /site/snippets/blocks/
title.php with code <?= $data->title() ?> is working fine and showing title, but “setlists” is not showing.

Here is my blueprint /site/blueprints/fields/builder.yml:

type: builder
fieldsets:
  setlists:
    label: Sarašas
    fields:
      lists:
        type: builder
        fieldsets:
          sarasas:
            label: Sąrašo elementas
            fields:
              title:
                label: Anšraštė
                type: text
              text:
                label: Tekstas
                type: textarea
  title:
    label: Antraštė
    fields:
      title:
        label: Antraštė
        type: text

Should it be the same template code or different for nested fieldsets?

<?php # /site/templates/yourtemplate.php
foreach($page->mybuilder()->toBuilderBlocks() as $block):
  snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach;
?>

if it’s different, what it should be and then also the question, how to have ability to sort parent fieldsets (I mean if there are two different codes, one will be above another always).

@timoetting, could you comment on this please?

are you using the most recent release? a similar issue has been fixed 18 days ago.

It was older, updated now, but still the same.

This issue https://github.com/TimOetting/kirby-builder/issues/113 is different, as it’s about first select list item, and I can’t show all nested fieldset.

just to veryify. it works properly if you use an type: textarea and/or type: structure instead of the nested type: builder?

Sorry, didn’t quite understand the question.

does a textarea work?

type: builder
fieldsets:
  setlists:
    label: Sarašas
    fields:
      lists:
        type: textarea
    label: Antraštė
    fields:
      title:
        label: Antraštė
        type: text

does a structure work?

type: builder
fieldsets:
  setlists:
    label: Sarašas
    fields:
      lists:
        type: structure
          fields:
            title:
              label: Anšraštė
              type: text
            text:
              label: Tekstas
              type: textarea
  title:
    label: Antraštė
    fields:
      title:
        label: Antraštė
        type: text

if both work nesting the builder is the problem.

Oh, I see, blueprint works fine, I only don’t know how to show nested fieldset on website in template.

:man_facepalming: ah i see. you need to call the builder again in the blocks snippet. something like this (untested).

/site/snippets/blocks/setlists.php

<?php
foreach($data->lists()->toBuilderBlocks() as $block):
  snippet('blocks/' . $block->_key(), array('data' => $block));
endforeach;
?>

Yes, something like this. I checked this code, seems that it should work, but getting error:

<?php foreach($block->lists()->toBuilderBlocks() as $subBlock): ?>
  <?= $subBlock->title() ?>
  <?= $subBlock->text() ?>
<?php endforeach ?>

P.S. in code using “lists”, in screenshot it’s “sarasas”, just checked, but result is the same :slight_smile:

you are forwarding block as $data so you need to use $data like in my example.

1 Like

Wow, it’s working, thanks a lot :slight_smile: Just I read another discussion, where it was suggested to use block, but maybe didn’t understand enough.

you are welcome. :heart:

1 Like