Jekyll pagination with data files

99 Views Asked by At

I was looking to try to do pagination with the _data files. Here is the code that I was coming up with but it doesn't work. Trying to make it work for a project I am working on right now for a nonprofit client I have.

{% if page.layout == "events" %}
    {% for events in paginator.events %}
    <div class="card card-posts">
        <img src="{{ events.image }}" class="card-img-top" alt="...">
        <div class="card-body">

            <h1 class="card-title my-3">{{ events.title }}</h1>

            <div class="meta-info">
                <ul class="list-inline">
                    {% if events.start %}
                    <li class="list-inline-item">
                        <i class="fas fa-calendar-alt"></i> {{ events.start | date_to_long_string }}
                    </li>
                    {% endif %}
                </ul>
            </div>

            <p class="card-text">{{ events.summary }}</p>

        </div>
    </div>
    {% endfor %}


    {% if paginator.total_pages > 1 %}
    <!--pagination-->   
    <div class="pagination bot-element">
        <div class="pr-bg pr-bg-white"></div>
        <div class="container">
            {% if paginator.previous_page %}
            <a href="{{ paginator.previous_page_path | prepend: site.baseurl }}" class="text-link"><i class="fal fa-long-arrow-left"></i></a>
            {% endif %}
            {% if paginator.page_trail %}
                {% for trail in paginator.page_trail %}
                <a href="{{ trail.path | prepend: site.baseurl }}" {% if page.url == trail.path %}class="current-page"{% endif %} title="{{ trail.title }}">{{ trail.num }}</a>
                {% endfor %}
            {% endif %}
            {% if paginator.next_page %}
            <a href="{{ paginator.next_page_path | prepend: site.baseurl }}" class="text-link"><i class="fal fa-long-arrow-right"></i></a>
            {% endif %}
        </div>
    </div>
    <!--pagination end-->
    {% endif %}
{% endif %}

Can someone see if this is a way possible that might have done this? If it is would it be ideal to do it for an events page to show an archive of events or no?

0

There are 0 best solutions below