(I should give back more to this forum)
TL;DR: How can you get the element number of a field part of a structured field?
$section->num()
does not obv work since it’s not a page.
I am building a multi-nested survey and want to build it and manage it from the panel. I am using Kirby Modules (w/ Kirby Sortable) together w/ Kirby Builder. And, I am nesting a modules inside another modules, though I read it’s not meant to work like that.
I’d like to number each module and section (which is part of a structure field from Kirby Builder), by combining the module number
with the section number
, eg:
1. Question A
1.1 Question B
1.2 Question C
I am using this for creating unique id
s and name
s for the input
tag, not for numbering a list item.
I can do the module numbering easily, since it is a subpage, by echoing
<?php echo $module->num() ?>
But when I try to call again the above code in the snippet (section
) field, I get an error of unknown variable.
Is there a way to traverse and going back from $data()
(the $section
object) to $module
? I tried to use $parent()
without success.
Using $section->num()
(actually $data->num()
) does not output anything, which I understand, since it’s not a page (unlike $module
).
I can use $section->count()
to get the number of objects in the collection, but how can I get the correct number for each element? I tried to use ->current()
(not knowing what it does), and it outputs NO
.
Furthermore: I am up to simplify this whole structure, by not nesting a $module
inside a $module
, and simply creating a fieldset
for Kirby Builder called fieldname_child
and then in its snippet syntax, building the correct numbering if that’s easier.