Skip to content

Having trouble creating individual events pages from _data/events.json #3687

Answered by pdehaan
cocodedesigns asked this question in Q&A
Discussion options

You must be logged in to vote

I fear this wasn't a satisfactory answer, and I was bored, so this might get you closer:

// events.11ty.cjs
exports.data = function () {
  return {
    pagination: {
      data: "events",
      size: 1,
      alias: "e",
      before(_, { events }) {
        return Object.entries(events).reduce((acc, [date, arr]) => {
          arr.forEach((event) => acc.push({ ...event, date }));
          return acc;
        }, []);
      },
    },
    layout: "event.njk",
    eleventyComputed: {
      date({ e }) {
        return new Date(`${e.date} ${e.time}`);
      },
      permalink({ e }) {
        return `events/${e.slug}/`;
      },
      title({ e }) {
        return e.event;
      },
    },
  };

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pdehaan
Comment options

pdehaan Mar 11, 2025
Collaborator

Answer selected by cocodedesigns
@cocodedesigns
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants