BTrem

11ty addTemplate

If you want to use virtual templates in an eleventy project, you have to use eleventy 3 or greater. But note that the feature landed – officially, at any rate – in 3.0 beta. In other words, 3.0 alpha is not necessarily good enough, as I learned today.[✲]

I was running 11ty version 3.0.0-alpha.5, as specified in my project’s package.json:

{
  "main": "eleventy.config.js",
  "dependencies": {
    "@11ty/eleventy": "3.0.0-alpha.5"
  }
}

If memory serves, that’s because when I first upgraded to 3.x, only an alpha version was available. Whatever the reason, when I tried addTemplate, 11ty threw an error: eleventyConfig.addTemplate is not a function.

After upgrading @11ty/eleventy – by entering npm install @11ty/eleventy at a terminal prompt – my package.json file was changed:

{
  "main": "eleventy.config.js",
  "dependencies": {
    "@11ty/eleventy": "^3.0.0"
  }
}

And the error disappeared.

notes

  1. I stumbled upon a mention of virtual templates in 11ty 3.0.0-alpha.15. So the feature may have been added to 11ty sometime between 3.0.0-alpha.5 and 3.0.0-alpha.15. But it was announced in 3.0 beta.

webmentions

add your webmention

Mention, like, or reply to this article from your site using webmentions. And if you do, let me know. Enter the url of your page in the form below and send it to me.