Menu icon Foundation
Insert current year/date in html

I generate my pages with panini and found out already how to use front matter to insert individual elements in the header, like title, keywords and description.

Now, I would like to insert the current year (or date) into my code.

Does anyone knows, if it is possible to use a variable for that?

I searched the internet but found nothing :(

paninicustom datafront matteryeardate

I generate my pages with panini and found out already how to use front matter to insert individual elements in the header, like title, keywords and description.

Now, I would like to insert the current year (or date) into my code.

Does anyone knows, if it is possible to use a variable for that?

I searched the internet but found nothing :(

This post has been closed. No new replies can be added.

Geoff Kimball over 3 years ago

The team behind Assemble, a Node-based static site generator, maintains a huge library of helpers. You might look there for some inspiration:

https://github.com/assemble/handlebars-helpers/tree/master/lib/helpers

Arkarys over 3 years ago

I just want to add that now I had time to try it out.
And, yes, it works. :D
Thanks Geoff

P.S. Do you have an idea where I can find more of these helpers / documentation? I'm not the brightest star in javascript.

Arkarys over 3 years ago

Wow, I will try this after christmas. Thanks, have a nice christmas :D

Geoff Kimball over 3 years ago

You can write a custom helper that dynamically inserts the date for you.

If you're using the ZURB Template (which you probably are), you can create a folder under src/helpers/, and put JavaScript files inside there that are helpers.

Make a file called year.js and add this code:

module.exports = function() {
  return new Date().getFullYear();
}

Panini will load in the helper using the filename, so the helper is called #year.

Now add {{year}} in your code and you'll get the year.