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.


Comments

If you liked this post, you might like these ones, too

  1. Convert a 2D array into a flat, 1D array of unique items

    Convert a messy multidimensional array into a nice single dimension array of unique items.

    Continue
  2. Create a JSON feed with 11ty

    🔥 A handy quick tip.

    Continue
  3. Use grayscale filter to see where you are relying too much on colour

    🔥 A handy quick tip.

    Continue

Become a supporter by joining the Piccalilli Membership

For as little a $5 per month, you can get access to a private, friendly community, get a weekly newsletter and help to make as much content free as possible around here. If you join the $10 per month supporters club, you get access to premium tutorials and free access to mini courses!

Become a member

Sign up for updates

Stay up to date with updates from Piccalilli. You’ll get alerted as soon as any new content gets published. You’ll also get updates on upcoming courses and membership features! You can unsubscribe at any time, too.