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

How can I display the contents of the blog page text for the first page only?

Solved by pamtbaau View solution

Started by dydaevskiy 8 years ago · 2 replies · 757 views
8 years ago

Hello, on the blog page there are more than 25 child pages, and of course when you open the blog appears pagination. But since the blog page has a description (that is, the text in the body of the blog page itself), this text is repeated on each page of the pagination. How can I get this text to appear on the first page of the blog?

8 years ago Solution

Looking at the pagination buttons at the bottom of a blog, it is clear that the pagination plugin knows if it is at the beginning, or end, of the collection of blog pages.

When digging into the plugin's template '/templates/pagination.html.twig', we can see the plugin uses the following to determine if it is NOT at the beginning of the collection:

TWIG
{% if pagination.hasPrev %}

where 'pagination' is defined at the top as:

TWIG
{% set pagination = pagination|default(page.collection.params.pagination) %}

Looking at the code of the plugin, it seems to extend the 'params' property of a collection. It adds a 'pagination' property, which provides methods like 'hasPrev()' and 'hasNext()'.

Solution:
You could try if the following works for you. Add these lines to template 'blog.html.twig':

TWIG
{% if not page.collection.params.pagination.hasPrev %}
    <h1>The text I only want to show on page 1</h1>
{% endif %}

I don't know for Helium/Gantry, but is does work for Quark.... ;-)

👍 1
last edited 09/15/18 by pamtbaau
8 years ago

Perfect solution! Many thanks, everything turned out!

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 days ago
2 84 2 days ago
General · by Andy Miller, 7 days ago
0 147 7 days ago
General · by Veehem, 1 week ago
0 146 1 week ago
General · by milkboy, 1 week ago
0 142 1 week ago
General · by ian russell, 2 weeks ago
2 226 2 weeks ago