That time of the year is coming up, so this trick will keep your website footer up to date on your Eleventy site.
First up: create a file inside of your _data
folder called helpers.js
and add the following to it:
- Code language
- js
module.exports = { currentYear() { const today = new Date(); return today.getFullYear(); } };
Now, on your templates, you can do something like this:
- Code language
- html
<footer role="contentinfo"> <p>Copyright {{ helpers.currentYear() }} My Awesome Site</p> </footer>
This trick uses JavaScript Data Files which I love using to create global helper functions like the above. They’re extremely handy and one of my favourite Eleventy features.