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.
Community guidelines
Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.
General
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.
TWIG
{% 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.
JS
var dates = [];
$('.blog-date').each(function(dateElement) {
dates.push(Date.parse(dateElement.text());
}
Log in to reply.
Suggested topics
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 2 | 74 | 6 hours ago | ||
| 1 | 47 | 10 hours ago | ||
| 0 | 43 | 23 hours ago | ||
| 6 | 346 | 5 days ago | ||
| 3 | 39 | 5 days ago |