Roman
May 21, 2019, 1:17pm
1
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).
Roman
May 21, 2019, 1:18pm
2
@timoetting , could you comment on this please?
are you using the most recent release? a similar issue has been fixed 18 days ago.
Roman
May 21, 2019, 2:20pm
4
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
?
Roman
May 21, 2019, 2:24pm
6
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.
Roman
May 21, 2019, 2:29pm
8
Oh, I see, blueprint works fine, I only don’t know how to show nested fieldset on website in template.
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;
?>
Roman
May 21, 2019, 2:49pm
10
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
bnomei
May 21, 2019, 2:50pm
11
bnomei:
array(‘data’ => $block)
you are forwarding block as $data so you need to use $data like in my example.
1 Like
Roman
May 21, 2019, 2:52pm
12
Wow, it’s working, thanks a lot Just I read another discussion, where it was suggested to use block, but maybe didn’t understand enough.