Hi I'm trying to access elements from the previous and next arrays. To be exact I want to access the previous and next url of pages. This is what I have done so far.Thanks!
{% assign page_venue = site.data.venues-array | where: "venueID", page.venue | first %
//This outputs the current url
{{venue.url}}
This is part of the yml file:
venueID: Red-Radish
name: Red Radish
url: redradish
building: 65
neighborhood: University Union
venueID: Poly-Deli
name: Poly Deli
url: polydeli
building: 19
neighborhood: University Union
venueID: Myrons
name: Myron's
url: myrons
previous: MustangStation
building: 19
neighborhood: University Union
So let's say I'm the second venue (Poly-Deli), I would like to see this:
Current url: polydeli
Previous url: reddish
Next url: myrons
I tried using the following to output the previous and next urls but it dindn't work:
<p>{{page.next.url}}</p>
<p>{{venue.next.url}}</p>
<p>{{paginate.next.url}}</p>
<p>{{paginator.next_page}}</p>
Someone helped me, and it did work, but it outputs the whole list. I just want to output something like this because this because I have 30 arrays(30 different venues):
Current url: polydeli
Previous url: reddish
Next url: myrons
And this is the code that outputs the whole list:
{% for venue in site.data.venues-array %}
{% assign next = forloop.index0 | plus: 1 %}
{% assign previous = forloop.index0 | minus: 1 %}
<div>Name: {{ venue.name }}</div>
<div>Current URL: {{ venue.url }}</div>
<div>Previous url:{{ site.data.venues-array[previous].url }}</div>
<div>Next URL is:{{ site.data.venues-array[next].url }}</div>
<hr>
{% endfor %}
As I've mentioned in my previous comment, I was not able to find a suitable plugin to paginate a
_datacollection. There are a few available but all require a lot of hacking plus they are quite bloated for such a simple requirement.You can add the following HTML and JS to the content part of your venues page. (I.e. underneath the front-matter).
HTML:
JavaScript:
You can change whether to keep looping or not by toggling the
infinitevariable as explained in the code's comments.Please note:
I have an older version of Jekyll on my system (v3.0.2) and thus the
jsonifyfilter breaks when there are single quotes in the text values of thevenues-array.yml. I.e. Myron's breaks and I could not escape it as shown below:If you have the Jekyll
>= 3.2then I believe you will not have this issue as Jekyll will automatically use theUTF-8encoding in advance of running the filter. I cannot upgrade my machine due to a client's site requiring this version and without a Docker container. If you do have this issue, try:1) Enforce UTF-8 on your yml file. or 2) Clean up single quotes in advance of the filter or 3) Don't use single quotes :)
Escaping did not work for me.
Other than that, all works perfectly as shown below: