verbb / footnotes

Craft CMS plugin for adding a footnotes feature to Redactor fields and Twig templates
MIT License
21 stars 2 forks source link

Matrix fields? #11

Closed zenbug closed 2 years ago

zenbug commented 2 years ago

Is there a way to make this work when the footnote is added a Matrix field? I'm not sure what the syntax would be for the line that converts footnotes into numbers without repeating it for every Matrix block:

{{ entry.handle_of_redactorfield | footnotes }}

dueddel commented 2 years ago

Sorry for the late response. I am not quite sure what you mean exactly. Could you explain a bit more, please?

(I woke up at 4 am this morning for no reason, as of writing this it's 6 am and I doubt being able to have a lucid mind right now. 😅)

zenbug commented 2 years ago

The docs say:

{# when accessing Redactor fields in your Twig template use the new filter #}
{{ entry.handle_of_redactorfield | footnotes }}

But that assumes that the footnotes have been entered into a standard Redactor field. My site has the redactor field inside a Matrix block, so entry.handle_of_redactorfield doesn't work.

I'm sure there's a way to make it work with Matrix fields but I don't know what it would be.

In short, how would you use this plugin when your field that holds the footnotes is in a Matrix block?

dueddel commented 2 years ago

Ah, thanks. Without trying I think it should work to simply iterate your Matrix blocks and add the footnotes filter to each block's Redactor field.

{# by accessing the matrix field a query object is retrieved #}
{# therefore call `all()` to get all blocks #}
{% for block in entry.handle_of_matrixfield.all() %}
  {# now simply access the redactor field as usual #}
  {{ block.handle_of_redactorfield | footnotes }}
{% endfor %}

That should do it. As said, I didn't try it, but I am slightly optimistic about it in general. 😁 Let me know if it worked.

PS: Pardon me any misspelled code or something, I am currently working a lot on a Symfony based project, thus I am not doing much Craft right now, unfortunately.

zenbug commented 2 years ago

I did try something like that, but it results in the footnotes being repeated multiple times throughout the page because it's running that footnotes filter again every time it encounters a Matrix block.

I appreciate the help with it anyway. The inability to include hyperlinks in the footnotes themselves is a dealbreaker for my client, so I don't think this plugin is right for me.

Thank you for contributing to the Craft ecosystem though!

dueddel commented 2 years ago

Okay, sorry that I can't help apparently. Feel free to fork it and add new features.

Also try that other footnote plugin from https://github.com/carlcs/craft-footnote: https://plugins.craftcms.com/footnote

That plugin has a different approach on adding footnotes (it also supports links in footnotes). Maybe that helps.