I’m having some trouble figuring this out. I’m using a jquery plugin (Scrollit) to scroll to parts of the page but i need to get Kirby to help out a little.
It works by giving elements and id in a data attribute:
Then you can scroll to it by putting a data attribute on an anchor tag:
But this is in a
foreach loop with Kirby Builder in it, so i need to get Kirby to automatically populate the INDEXNUMBER for me, and for the link tag it needs to add 1 to it, since this will make scroll on to the next builder panel on the page.
My code looks like this (some of it is slightly fake to illustrate what i need in words).
<?php foreach($page->builder()->toStructure() as $section): ?> <?php $INDEXNUMBER = $theforeachindex ?> <div class="builder-block" data-scroll-index="INDEXNUMBER"> <?php snippet('builder/' . $section->_fieldset(), array('data' => $section)) ?> </div> <a data-scroll-goto="INDEXNUMBER+1" target="_blank" class="pagenav"><i class="fa fa-chevron-down" aria-hidden="true"></i></a> <?php endforeach ?>
How do i get Kirby to count the number of items in the foreach loop and fill in the numbers, and also how would i get to start from a set number? Some pages already have these numbers hard coded further up the page so i might to start the numbering on the builder panels from an arbitrary number.