Is there a way to collect all dates from my blog posts? The reason I am asking is that I want to activate only the dates i a datepicker, where blogposts exist.
I’m guessing you’re using javascript for this right?
In twig, you could loop through all of the blog posts and just output their date.
Something like this.
{% set collection = page.collection({ 'items': { '@self.descendants' }) %} // If you are on the page that holds all the blog posts
{% for post in collection %}
<div class='hidden blog-date'>{{post.date}}</div> // Whatever date value you're using
{% endfor %}
Or you could install this Grav Pages as Data plugin, and get the data using AJAX, or whatever you use for HTTP Requests.
That looks good, thank you.
Another question: I want to pass these dates to the jquery datepicker. I have to do this as array. Can i collect these dates in an array instead of writing them out?
Something like this should work if you’re using jQuery. It should get you on the right track at least.
var dates = [];
$('.blog-date').each(function(dateElement) {
dates.push(Date.parse(dateElement.text());
}