11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.77k stars 484 forks source link

access eleventyConfig plugin property #3214

Open btrem opened 6 months ago

btrem commented 6 months ago

Discussed in https://github.com/11ty/eleventy/discussions/3193

Originally posted by **btrem** February 7, 2024 I have several plugins in my site setup, which are listed in the `eleventyConfig` in a `plugins` array (shortened for ease of reading): ``` plugins: [ { plugin: [AsyncFunction (anonymous)], options: undefined, pluginNamespace: '' }, { plugin: [Function (anonymous)], options: undefined, pluginNamespace: '' } ] ``` One of my plugins has a `pluginConfig` that I can access via `eleventyConfig.plugins[1].options.foo`. Can I find this particular property directly? I.e., is there a way to access the plugin via it's name in the .eleventy.js `addPlugin` directive? I tried `JSON.stringify(eleventyConfig.plugins["myPlugin"])` and got undefined.
zachleat commented 4 months ago

Per the recently merged docs here: https://www.11ty.dev/docs/plugins/#creating-a-plugin, I believe the options are passed in as a second argument—is that what you mean?

btrem commented 4 months ago

[meta: I replied to this logged into a sibling's GH account; I apologize for my carelessness]

The options are passed in to the plugin as that link describes, and are available in the main plugin file, e.g. myPlugin/index.js. But how do I access the options object in other files? In my case, specifically, in other files that are part of the plugin, e.g., myPlugin/myFilter.js?

saiballo commented 3 months ago

I have the same problem. Did you solve it?