Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Pagination of translated pages not working properly

Solved by Marco Cevoli View solution

Started by Marco Cevoli 5 years ago · 6 replies · 499 views
5 years ago

Hi,
I'd like to fix this issue we're having on our company's site.
If you compare the Italian (original) blog page with English blog page, you'll see that pagination on the English blog is not correct. There are pages with 1 or 2 articles, and others with 6-8 articles.

Apparently, the blog page uses the Italian pagination and then simply shows empty slots if an Italian article hasn't been translated to English.

This is the code of blog.html.twig. Any help will be appreciated.

TWIG
{% extends 'partials/base.html.twig' %}

{% block content %}
  {% include 'partials/banner2.html.twig' %}

<!-- Search box -->
<div class="container">
    <div class="row">
        <div class="col-lg-12 col-md-12">
            {{ content|raw }}
        </div>
    </div>
<div class="row">
<div class="col-lg-12 col-md-12">
{% include 'partials/simplesearch_searchbox.html.twig' %}
</div>
</div>
</div>
  <!-- ============================ Blog Grid Start ================================== -->
  {% set collection = page.collection() %}
  <section>
    <div class="container">
        <div class="row">
        {% for child in collection %}
            {% if child.language == grav.language.getLanguage %}
            <!-- Single Blog Grid -->
            <div class="col-lg-6 col-md-6">
                <div class="blog-grid-wrap mb-4">
                    <div class="blog-grid-thumb">
                        <a href="{{ child.url }}">
                <img src="{{ child.media.images|first.url() }}" class="img-responsive" alt="" />
              </a>
                        <div class="bg-cat-info">
                            <h6>{% for cat in child.header.taxonomy.category %}{{ cat }}{% if not loop.last %},{% endif %} {% endfor %}</h6>
                            <span>{{ child.header.date|date('d') }} {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(child.header.date|date('n') - 1) }} {{ child.header.date|date('Y') }}</span>
                        </div>
                    </div>
                    <div class="blog-grid-content">
                        <h4 class="cnt-gb-title">
                <a href="{{ child.url }}">{{ child.title }}</a>
              </h4>
                        <p>{{ child.summary(110)|striptags }}</p>
                    </div>
                    <div class="blog-grid-meta">
                        <div class="gb-info-author">
                            <p><i class="fa fa-user-circle-o"></i> {% for author in child.taxonomy.author %}{{ author }}{% if not loop.last %},{% endif %} {% endfor %} <span class="reading-time"> <i class="fa fa-clock-o"></i> {{ child.content|readingtime }}</span></p>
                        </div>
                    </div>
                </div>
            </div>
            {% endif %}
        {% endfor %}
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="bs-example">
            {% include 'partials/pagination.html.twig' with {'base_url':page.url, 'pagination':collection.params.pagination} %}
                </div>
            </div>
        </div>

    </div>
  </section>
  <div class="clearfix"></div>
  <!-- ============================ Blog Grid End ================================== -->
{% endblock %}

I'd like to have 8 articles on each page, regardless of the language. So, page 1 of the English blog should show the latest 8 English articles, even though these articles don't match the Italian ones.

I hope it's clear. If it isn't, I'll be happy to explain further.

Thanks in advance,

Marco

5 years ago

Do frontmatters of both blog[.it]?.md and blog.en.md match for the list part?

5 years ago

Yes, they do (except description and metadata values):

YAML
---
title: Blog
content:
    items: '@self.children'
    order:
        by: date
        dir: desc
    limit: 8
    pagination: true
description: '“Under the Hood”, Qabiria’s blog dedicated to translation, copywriting, business writing, effective writing and internationalization. Read all the posts.'
metadata:
    keywords: translation blog, blog on translation, blog on internationalisation, blog on business writing, blog on writing, blog on copywriting
---
5 years ago Solution

@Karmalakas , you hinting at the frontmatter made me think that the issue was indeed related to the way Grav creates the collection. I've found a thread on Github (https://github.com/getgrav/grav/issues/2985) that suggested to add

YAML
  content_fallback:
    en: en
    it: it
    es: es

to the system.yaml configuration file.
That did the trick. I still have to check the rest of the site, to be 100% sure that this configuration hasn't broken anything else...

Thanks!

Marco

👍 1
5 years ago

Sorry, I spoke too soon. I now see the same wrong behaviour. Not sure if it has to do with cache... I'll try on other computer and report back here...

5 years ago

ok, here's my findings: for reasons that I don't know, if you go to the backend and access the Configuration > Language tab, Grav doesn't allow you to set fallback from a language into the same language. So, en: en becomes en: en,es,it, which causes the above error.
However, if I leave the backend page and manually edit system.yaml, then I can set the fallback configuration as above and the pagination is correct.

I think there is another bug or misbehaviour on the backend/admin page, because Grav is repeatedly asking me that there are "unsaved changes" even though I correctly saved the page before leaving the page. I'm not sure what is causing this, but I'll open another thread if this issue persists.

👍 1
5 years ago

Maybe worth submitting a ticket also on GH. Just not sure to main Grav repo or Admin 🤔

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 49 1 week ago
Plugins · by Xavier, 4 weeks ago
2 57 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1184 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 75 2 months ago