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

Hello, I’m Andy and I’ll help you to level up your front-end development skills.

I'm a designer and front-end developer who has worked in the design and web industries for over 15 years, and in that time, I have worked with some of the largest organisations in the world, like Google, Harley-Davidson, BSkyB, Unilever, The Natural History Museum, Oracle, Capita, Vice Media and the NHS.

On Piccalilli, I share my knowledge and experience to make you a better front-end developer.

I'm the founder of Set Studio, a creative agency that specialises in building stunning websites that work for everyone. Check out what we're all about.