-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
this.eleventy is not available in JavaScript template functions #2790
Comments
Switched my code to |
Hmm, gonna milestone this into 2.0.1 for now! |
I have a probably related issue where
const paths = new Map([['text', 'notes']])
module.exports = class Redirects {
data() {
return {
layout: null,
permalink: '_redirects',
eleventyExcludeFromCollections: true,
}
}
createLegacyRedirects(collection, currentBase) {
const { slugify } = this
return collection
.map(function (item) {
const { permalink, external } = item.data
if (external) return ''
const cleanedPermalink = permalink.replace(`/${currentBase}/`, '')
const redirects = []
if (item.data.oldTitles) {
item.data.oldTitles.forEach(function (title) {
redirects.push(
`/${currentBase}/${slugify(title)}/ ${permalink} 301`,
)
})
}
if (paths.get(currentBase)) {
redirects.push(
`/${paths.get(currentBase)}/${cleanedPermalink} ${permalink} 301`,
)
}
return redirects.join('\n')
})
.join('\n')
}
render({ collections }) {
const { blog, notes, aroundTheWeb } = collections
return `
https://11ty.owlish.dev/* /:splat 301
https://reading.ovl.design/* https://www.ovl.design/around-the-web/ 301
/atw /around-the-web/ 301
${this.createLegacyRedirects(blog, 'text')}
${this.createLegacyRedirects(notes, 'notes')}
`.trim()
}
} |
That’s not related to Eleventy, it’s the way JS works. If you use arrow functions for |
Sorry, but I know «the way JS works». Those were arrow functions and it worked in v1 and broke after updating to v2. I just forgot to change it back before commenting. For context, debugger screenshots. I tried to bind this in the class constructor with
Appreciate any useful tips. |
I see — that looks like a different issue where |
But I can't do |
|
Shipping witih 2.0.1—thank you! |
Operating system
macOS Ventura 13.2 (22D49)
Eleventy
2.0.0-beta.3
Describe the bug
When creating a shortcode in any other template language,
this.eleventy
is available as described in the docs. However, for a function added withaddJavaScriptFunction
, thethis
property does not have aneleventy
property.Reproduction steps
npm install; npm run build
Expected behavior
_site/example/index.html
contains the useful content ofthis.eleventy
Actual behavior: the property is missing
Reproduction URL
https://gist.github.com/j-f1/8127173e227be4af465c1ad9063f95d0
Screenshots
No response
The text was updated successfully, but these errors were encountered: