Footnotes plugin and blocks

Hey everyone,
I am using this plugin for footnotes: GitHub - sylvainjule/kirby-footnotes: Footnotes plugin for Kirby 3 and I have troubles getting it to work with blocks.

In the docs it says that there is only a temporary solution so far:
this is in blogpost.yml:

<?php $blocks  = $page->text()->toBlocks();
      $startAt = 1;
      $notes   = [];
      $applyTo = ['text', 'markdown']; ?>

      <div class="text-container">
        <?php foreach($blocks as $block):
              if(in_array($block->type(), $applyTo)):
                  // we get the text with footnotes references but no bottom footnotes container
                  $text     = $block->text()->withoutBlocksFootnotes($startAt);
                  // instead, we get an array of the block's footnotes, and append it to our $notes array
                  $notesArr = $block->text()->onlyBlocksFootnotes($startAt);
                  if($notesArr !== '') {
                    foreach($notesArr as $f) { $notes[] = $f; }
                  }
                  // the first note of the next block will now start at (number of current notes + 1)
                  $startAt = count($notes) + 1;
                  echo $text;
              else:
                echo $block;
              endif;
              endforeach; ?>
        </div>
        // if there were notes
        <?php if(count($notes)): ?>
        <div class="notes-container">
            // we manually call the 'footnotes_container' snippet
            <?php snippet('footnotes_container', ['footnotes' => implode('', $notes)]) ?>
        </div>
        <?php endif; ?>

Unfortunately, I have troubles getting even the temporary solution to work.

        fieldsets:
          - heading
          section:
            name: section
            tabs:
              content:
                 fields:
                    headline:
                      type: text
                    text:
                      type: textarea
                    lastUpdated:
                      type: date
                      display: MM/DD/YYYY

the block snippet section.php looks like this:

<div class="chapter">
  <div class="chapter-background">
    <?= $block->headline()?>
  </div>

  <article class="row">
    <?= $block->text()->footnotes()?>
  </article>
</div>

Lastly I have my page blogpost.php:

<?php snippet('header') ?>

<?php $blocks  = $page->text()->toBlocks();
      $startAt = 1;
      $notes   = [];
      $applyTo = ['text', 'markdown']; ?>
      <div class="text-container">
        <?php foreach($blocks as $block):
              if(in_array($block->type(), $applyTo)):
                  // we get the text with footnotes references but no bottom footnotes container
                  $text     = $block->text()->withoutBlocksFootnotes($startAt);
                  // instead, we get an array of the block's footnotes, and append it to our $notes array
                  $notesArr = $block->text()->onlyBlocksFootnotes($startAt);
                  if($notesArr !== '') {
                    foreach($notesArr as $f) { $notes[] = $f; }
                  }
                  // the first note of the next block will now start at (number of current notes + 1)
                  $startAt = count($notes) + 1;
                  echo $text;
              else:
                echo $block;
              endif;
              endforeach; ?>

        </div>
        <?php if(count($notes)): ?>
        <div class="notes-container">
            <?php snippet('footnotes_container', ['footnotes' => implode('', $notes)]) ?>
        </div>
        <?php endif; ?>

<?php snippet('footer') ?>

Here I make use of the temporal solution provided. Yet, it renders each block individually with the footnotes after the respective blocks. As a result, the footnotes for each blog start with β€œ1” instead of being calculated accross the page – which the solution was supposed to solve.

Did anybody use this plugin before and got it to work with blocks?

1 Like

Never used the plugin, but calling footnotes() here is probably the issues and defeats the purpose of the workaround.

And the other hand the workaround is only applied to the text and markdown blocks, not the custom section block.

I didn’t realize that it is meant for text and markdown blocks. Do you know about any way to make footnotes work with custom blocks?

This array defines which types of blocks the workaround is applied to. So I would add the custom block to this array.

1 Like

Right, I didn’t realize that I could just add things here. It works perfectly – thanks!