You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<html>
<body>
<p>{% works %}</p>
<p>{% fails %}</p>
</body>
</html>
Expected behavior
I would have expected the arrow function to work, but if that is not possible due to some technical reason, then a more informative error would have been great.
Reproduction URL
No response
Screenshots
No response
The text was updated successfully, but these errors were encountered:
Actually, it looks like some other issue is at play here. I don't know what's triggering it, but I have been making other unrelated changes to the templates that cause the same error to occur, even with standard function() { ... } syntax.
If I then update the function to change it, it starts working again:
original code
eleventyConfig.addShortcode("year", function () {
return new Date().getFullYear();
});
< make some unrelated change to a template >
[11ty] 1. Having trouble writing to "./_site/index.html" from "./src/index.njk" (via EleventyTemplateError)
[11ty] 2. (./src/includes/base.njk) [Line 20, Column 18]
[11ty] unknown block tag: year (via Template render error)
❌ Compile fails
< make a change to the shortcode function >
eleventyConfig.addShortcode("year", function () {
return new Date().getFullYear();
// add a comment here that doesn't change anything
});
✅ Everything compiles again
Hypothesis: there is some kind of optimization that is happening which removes this function from scope on a rebuild when a template changes.
jmole
changed the title
arrow function in short codes doesn't work
No-arg shortcode functions randomly fail
Mar 5, 2025
Read comment 1, I have a new hypothesis for this bug.
Operating system
macOS
Eleventy
3.0.0
Describe the bug
I ran into this issue when learning 11ty while prompting Claude 3.7.
I wanted a way to include a string in a template, and claude recommended a shortcode:
However, trying to use this in a njk template yielded mixed results. Sometimes it appeared to work, other times, it failed to build:
Playing around for a while, I found that if I wrote the function like so, it would work:
Reproduction steps
Use an arrow function to define a short code.
And use in an njk template:
Expected behavior
I would have expected the arrow function to work, but if that is not possible due to some technical reason, then a more informative error would have been great.
Reproduction URL
No response
Screenshots
No response
The text was updated successfully, but these errors were encountered: