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

Error: filter not found: toc (via Template render error) #43

Open
hegedusgergely opened this issue Jun 2, 2023 · 1 comment
Open

Error: filter not found: toc (via Template render error) #43

hegedusgergely opened this issue Jun 2, 2023 · 1 comment

Comments

@hegedusgergely
Copy link

hegedusgergely commented Jun 2, 2023

Environment

Node version: 19.8.1
OS/version: macOS 13.4

Eleventy

Eleventy version: 2.0.1
Template engine: njk
Sample input file: what does it mean?

Plugin

Plugin module version: 1.1.5
Plugin settings object (if used): tags: ['h2', 'h3'], wrapper: 'div'
Plugin use in template:

{% if content | toc %}
  <aside class="md:sticky md:top-10 p-4 bg-rose-50 rounded-xl">
      {{ content | toc | safe }}
  </aside>
{% endif %}

Description of the issue

Followed through the instructions as closely as I could but on build 11ty throws an error.

I was able to fix it with some trial and error (I'm no developer) but it sure feels like a hack.

In .eleventy.js added globalOpts to module.export and copy pasted the filter from this repo's .eleventy.js like this:

module.exports = function (eleventyConfig, globalOpts) {
    globalOpts = globalOpts || {}
    eleventyConfig.namespace(globalOpts, () => {
        eleventyConfig.addFilter('toc', (content, localOpts) => {
        return buildTOC(content, parseOptions(localOpts, globalOpts))
        })
    });
}

I have `markdown-it-anchor' installed and working.

Desired output

I expected to see a list of links in the <aside> of the layout.

Actual output

[11ty] 1. Having trouble writing to "_site/blog/2020-review-koltozes-az-elso-covid-19-hullam-kellos-kozepen/index.html" from "./blog/2020-review-koltozes-az-elso-covid-19-hullam-kellos-kozepen.md" (via EleventyTemplateError)
[11ty] 2. (./_includes/post-layout.njk)
[11ty]   Error: filter not found: toc (via Template render error)
[11ty]
[11ty] Original error stack trace: Template render error: (./_includes/post-layout.njk)
[11ty]   Error: filter not found: toc
[11ty]     at Object._prettifyError (/opt/homebrew/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/lib.js:32:11)
[11ty]     at /opt/homebrew/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/environment.js:464:19
[11ty]     at Template.root [as rootRenderFunc] (eval at _compile (/opt/homebrew/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/environment.js:527:18), <anonymous>:32:3)
[11ty]     at Template.render (/opt/homebrew/lib/node_modules/@11ty/eleventy/node_modules/nunjucks/src/environment.js:454:10)
[11ty]     at /opt/homebrew/lib/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:411:14
[11ty]     at new Promise (<anonymous>)
[11ty]     at /opt/homebrew/lib/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:410:14
[11ty]     at TemplateLayout.render (/opt/homebrew/lib/node_modules/@11ty/eleventy/src/TemplateLayout.js:236:31)
[11ty]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[11ty]     at async Template.renderPageEntry (/opt/homebrew/lib/node_modules/@11ty/eleventy/src/Template.js:793:17)
@smirs
Copy link

smirs commented May 27, 2024

I have the same issue, thanks for posting

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

No branches or pull requests

2 participants