Remove first line in summary with twig


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


First line (this would be deleted)

“Rest of the summary text …”


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

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

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

1 Like


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:

The page shows:

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

I hope this help you to understand my intention.

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

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 :thinking: Then in your page twig template you should change to show title instead of summary

I’ve found a simple solution.

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

{% block content %}
    {{ page.content|raw }}
{% endblock %}

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

Thanks for your help.