Check if publish date has been reached


I am just starting out with Vapid. I need to compare a date set in a section (publish date), with the current date. So posts don’t appear until the publish date. Is there a way to get the current date in Vapid?

Hello Mike!

You can use JavaScript to get the current date and compare it to the publishing date of your posts. For example, you could do this:

<section id="posts"></section> <!-- Posts will be put here -->

{{#section posts multiple=true}}
    // Creates a template field for the publishing date in Vapid’s dashboard
    const pubDate = new Date("{{publishing_date type=date format=%F}}");

    const date = new Date();

    // Compare the current date with the publishing date
    if (date >= pubDate) {
      // Create new DOM element for post
      var post = document.createElement("div");

      // Add content to the post element
      post.innerHTML = "{{content}}";

      // Append post element to the posts section