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.

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 · 647 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 Jerry Hunt, 4 days ago
2 99 16 hours ago
General · by pamtbaau, 21 hours ago
1 63 21 hours ago
General · by Andy Miller, 1 day ago
0 48 1 day ago
General · by Marcel, 12 months ago
6 357 5 days ago
General · by Duc , 6 days ago
3 45 6 days ago