Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing term definitions #5

Closed
storybynumbers opened this issue Jun 16, 2022 · 6 comments
Closed

Missing term definitions #5

storybynumbers opened this issue Jun 16, 2022 · 6 comments
Assignees

Comments

@storybynumbers
Copy link
Contributor

I am applying the glossary to a field within a repeating matrix block, and running into this error:

Glossary.js?v=1655385555:formatted:1947 Uncaught TypeError: Cannot read properties of null (reading 'innerHTML')
    at content (Glossary.js?v=1655385555:formatted:1947:46)

Words are underlined properly, but the #glossary-terms element is missing a number of definitions.

@kringkaste kringkaste self-assigned this Jun 17, 2022
@kringkaste
Copy link
Member

Hi @storybynumbers which version of the plugin and Craft CMS do you run?

@kringkaste
Copy link
Member

For testing, I created a matrix field with a single block with one plain text field in it. Then I added this field to a section. Add an entry in the section and added multiple blocks with the field. In my template I added the following:

{% for block in craft.entries.slug("my-first-article").one().matrix.all() %}
{{ block.contentField|glossary }}
{% endfor %}
{% hook 'glossary-terms' %}

And this works as expected, Did I miss something?

@storybynumbers
Copy link
Contributor Author

Hi @kringkaste, thanks for the quick response and sorry for my slow one!

  • Craft CMS: 3.7.45.1
  • Glossary: 1.0.5

I'm encountering the issue when there are multiple blocks. I have a page with three blocks, and only definitions from the last block are included in #glossary-terms. The terms in all three blocks are properly highlighted, but a JS error is thrown when hovering over a term in the first two blocks which is not included in the last one.

Some more context:

  1. I'm including {% hook 'glossary-terms' %} at the entry template level
  2. My entry template loops through a matrix field like so
{% include '_blocks/blocks.twig' with { blocks: entry.blocks } %}

This is my _blocks/blocks.twig template:

{% for block in blocks.all() %}
  {% set blockType = (block.type | kebab) %}
  {% set file = '_blocks/' ~ blockType ~ '/' ~ blockType ~ '.twig' %}
  {% include file with {block: block } %}
{% endfor %}
  1. The mini-template where the filter is finally used looks something like this (I'm over-simplifying but this reproduces the problem for me)
{% set glossary_lang = 'glossary_' ~ craft.app.locale|slice(0,2)|lower %}
{{ block.block1Text|glossary(glossary_lang) }}

@storybynumbers
Copy link
Contributor Author

Hi @kringkaste, I was able to narrow the issue down. Every time the glossary filter is applied, the list of used terms is reset. It doesn't accumulate across multiple calls. So it's not an issue with the matrix field, it's an issue with applying the glossary multiple times.

@kringkaste
Copy link
Member

Hi @storybynumbers ! Thanks for the debugging and the PR.

@kringkaste
Copy link
Member

Fixed in release 1.0.6 for Craft 3 and 2.0.1 for Craft 4. Thanks for debugging and providing a PR!

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

No branches or pull requests

2 participants