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

Remove first line in summary with twig

Solved by Pedro M View solution

Started by Pedro M 4 years ago · 7 replies · 932 views
4 years ago

Hi.

Is possible to remove the first line in the summary text with some twig filter??.

Example:

First line (this would be deleted)

"Rest of the summary text ......"

Thanks.

4 years ago

What does "first line" mean. What size screen? How many characters?

4 years ago

Hi.
The first line means up to the first line break, regardless of the characters that line has.

4 years ago

What's the use case? Why that line exists in the summary if it needs to be removed?

👍 1
4 years ago

ok

I have in main page several cards that show some articles in a specific category, and they show the summary of the page. When you click in some card it shows the whole page. For example:

card_main_page|390x500

The page shows:

page_with_all_text|690x259

I'd like that first line would be hidden in summary (in cards).

I hope this help you to understand my intention.
Thanks.

4 years ago

If I understand correctly, you're showing summary as a title in the item page, but you have a separate title shown in a card. Why can't you just remove summary in your content and just have a title? Summary is not supposed to be used as a title.

If you still need both summary and title, but don't want to show summary in some places, check this recipe how to remove summary from content
https://learn.getgrav.org/17/cookbook/twig-recipes#displaying-page-content-w

4 years ago

BTW, could you share how this .md file looks like? I suspect the approach might be wrong here. According to your screenshots, there should be just title and content without a summary. Card shows truncated content, which would mean there's no real summary there or at least it's not needed AFAIK 🤔 Then in your page twig template you should change to show title instead of summary

4 years ago Solution

I've found a simple solution.

I've modified the default.html.twig adding the page.title like a separated element:

TWIG
{% block content %}
    <h2>{{page.title|raw}}</h2>
    {{ page.content|raw }}
{% endblock %}

Summary only works with the content, not with page.title.

Thanks for your help.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago