Kirby builder + kirby footnotes: merge footnotes in one list

In short:

I’m using kirby builder to add multiple textblocks to an page in the panel. And am outputting footnotes from each textblock with kirby footnotes. All good.

One problem of course, is that kirby footnotes in this setup generates footnotes for each textblock. So I tried to solve this like here

  1. collect all textblocks in an array
  2. merge array into one string
  3. cast new object to pass to kirby footnotes
$txs = [];
foreach($page->builder()->toStructure()->filterBy('_fieldset', 'textblock') as $tx) {
  array_push($txs, $tx);
};

$txs = implode("\n\r", $txs);

$fts = array(
  'text' => array('value' => $txs)
);
$ftt = json_decode(json_encode($fts));

echo KirbyFootnotes::bibliography($ftt->text()->kt());

now that i pass my custom object ($ftt), kirby says

Call to undefined method stdClass::text()

Would you suggest to use, to avoid the undefined method above?
Making a kirby custom field method to call like this

echo KirbyFootnotes::bibliography($myCustomMethod->text()->kt());

mmh with a kirby extended field i can’t pass an argument to it, it seems.

in my case i should be able to somehow pass the string $txs.

Its late and my eyes are weary but i think the problem is that very last line…

echo KirbyFootnotes::bibliography($ftt->text()->kt());

I think you have ended up with a string and your trying to do field stuff with it but its no longer a field. I think the proceeding code is an attempt to combine the fields so that Kirby thinks its one single field. I dont think thats the way to do it, but i also dont know the correct way. Im sure someone with a bigger brain then mine will be along soon…

…but my guess is that its expecting text() to be a field. What happens if you do:

echo KirbyFootnotes::bibliography($ftt->kt());

If i understand your code correctly youve set $ftt programmatically to be a field as far as Kirby is concerned. Assuming you’ve done that right, then going straight into kt() should work i think.

hey thanks!

if i do ...($ftt->kt()) i still get the same error of

Call to undefined method stdClass::kt()

i think the problem here might be the generic, non-kirby class i created to host all the merged footnotes.

looks like though that also just calling something like this

a::show($ftt->text());

gives me the above undefined method error. therefore i think it’s my generic class being done wrong.

the hacky alternative would be to just adjust styles and replace all footnotes numbers with js, but meh.

I think you are overcomplicating your code.

<?php 
$txs = [];
foreach($page->article_builder()->toStructure()->filterBy('_fieldset', 'textblock') as $tx) {
  array_push($txs, $tx->text());
};
$txs = implode("\n\r", $txs);

$ftt = new Field($page, null, $txs);

echo KirbyFootnotes::bibliography($ftt);
1 Like

this is exactly what i thought i should do!

amazing, thanks a lot. super tight and elegant :stuck_out_tongue:

Thinking about it though, you still have a problem. What @texnixe just posted will generate the list of footnotes in the right order under all the builder textfields but the superscript numbers within the text that links to them will still be numbered from one for each text block, so now you need to fix those?

yes! will evaluate if just hacking it with js on the fly, or see if there’s a php easy-enough way to mend it as well.

the footnotes were the most important thing imo.

i’ll share the final code if you’re interested :slight_smile:

Ok. You might get away with CSS counters rather then a JS hack job.

i still need to adjust the correct href for the sup though!

Oh yes of course u do. Javascript it is then. Might have SEO implications though. Search engines are getting clever these days, but theres a chance they might see the original links before they have been manipulated with javascript.

ah! mmh. the quick and dirty js code works okay.

else i should fork the footnotes plugin and figure out something together with kirby builder, but feels overkill for now.

and in this case, SEO-wise, the links are just #fn-1, #fn-2, etc.

thinking about it, having a fork of kirby footnotes to be context-aware of multiple text fields would be nice :stuck_out_tongue:

Sure, I know they are only internal links but i’ve got a feeling they will get seen as broken links if it doesn’t match up with a corresponding element on the page though.

I wouldn’t care about SEO too much in this context.

The footnotes plugin has been archived, no idea if there are plans to port it to Kirby 3.

But yes, in contexts with multiple text fields that form a unit, it would make sense to have an option.