Skip to content

Instantly share code, notes, and snippets.

@carlcs
Last active November 4, 2019 09:59
Show Gist options
  • Save carlcs/a8c51bb7bbeb3350e549a6ba3cd27f7a to your computer and use it in GitHub Desktop.
Save carlcs/a8c51bb7bbeb3350e549a6ba3cd27f7a to your computer and use it in GitHub Desktop.

Footnotes plugin 2.0.0-beta.5

Redactor Settings

Add "footnote" to the "plugins" setting. You can optionally define the button's position in the toolbar with the "footnoteAddAfter" setting.

"plugins": ["footnote"],
"footnoteAddAfter": "lists",

Templating Examples

Basic Example

{% do parseFootnoteDefinitions(entry.footnotes) %}
{{ entry.text|parseFootnoteMarkers }}
{{ getFootnotesHtml() }}

Custom Templates

{% do parseFootnoteDefinitions(entry.footnotes) %}
{{ entry.text|parseFootnoteMarkers('_includes/footnotes/marker') }}
{{ getFootnotesHtml('_includes/footnotes/list') }}

Multiple Articles

{% for entry in entries %}
    {% do parseFootnoteDefinitions(entry.footnotes, entry.slug) %}
    {{ entry.text|parseFootnoteMarkers(null, entry.slug) }}
    {{ getFootnotesHtml(null, entry.slug) }}
{% endfor %}

Usage with a Matrix Field

{% for block in blocks if block.type == 'footnotes' %}
    {% do parseFootnoteDefinitions(block.footnotes) %}
{% endfor %}

{% for block in blocks if block.type != 'footnotes' %}
    {% if block.type == 'text' %}
        {{ block.text|parseFootnoteMarkers }}
    {% endif %}
{% endfor %}

{{ getFootnotesHtml() }}

Usage with an array of note definitions (e.g. from a Super Table)

{% do setFootnoteDefinitions({
    a: 'My footnote',
    b: 'Another footnote',
}) %}
{{ text|parseFootnoteMarkers }}
{{ getFootnotesHtml() }}

Note: Twig doesn’t allow to set and merge hashes with numberical indexes. To work around that issue and still allow to use numberical footnote definition indexes, prefix your numbers with ಠvಠ before passing them to setFootnoteDefinitions. The plugin will strip these ASCII characters, and they will get matched to the corresponding numerical marker indexes.

{% set definitions = {} %}
{% for row in entry.footnotes.all() %}
    {% set definitions = definitions|merge({ ('ಠvಠ' ~ row.footnoteId): row.footnoteText }) %}
{% endfor %}
{% do setFootnoteDefinitions(definitions) %}

{{ text|parseFootnoteMarkers }}
{{ getFootnotesHtml() }}
@KatieMFritz
Copy link

This is very cool!

I'm trying to get the last example working (aggregating footnotes from across supertable rows), but I'm not sure where you're getting the footnoteId and footnoteText properties.

My supertable is set up like this (simplified a bit here):

paperContentBlocks
- sectionContent (this is the redactor field with footnote links)
- footnotes

How do I access footnoteId and footnoteText from that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment