Dynamic footer copyright date in Eleventy

Categories

That time of the year is coming up, so this trick will keep your website footer up to date on your Eleventy site.


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
JavaScript
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.

Hello, I’m Andy and I’ll help you build fast & visually stunning websites.

I am currently setting up a new creative agency called Set Creative Studio and we are taking on projects for 2022, so if you have a project in mind, get in touch.