-
-
Notifications
You must be signed in to change notification settings - Fork 557
Closed
Labels
bug: --serve restartChanges to projects shouldn’t need to restart dev serverChanges to projects shouldn’t need to restart dev server
Milestone
Description
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:
// Add a shortcode for the current year
eleventyConfig.addShortcode("year", () => {
return new Date().getFullYear();
});
However, trying to use this in a njk template yielded mixed results. Sometimes it appeared to work, other times, it failed to build:
<p>© {% year %} All rights reserved.</p>
[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)
Playing around for a while, I found that if I wrote the function like so, it would work:
eleventyConfig.addShortcode("year", function () {
return new Date().getFullYear();
});
Reproduction steps
Use an arrow function to define a short code.
eleventyConfig.addShortcode("works", function () {
return "works"
});
eleventyConfig.addShortcode("fails", () => {
return "fails"
});
And use in an njk template:
<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
Metadata
Metadata
Assignees
Labels
bug: --serve restartChanges to projects shouldn’t need to restart dev serverChanges to projects shouldn’t need to restart dev server