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 to hide content before === delimiter in article view?

Started by Dima 2 years ago · 13 replies · 204 views
2 years ago

I need to hide the summary content (everything before the === delimiter) when viewing a full article in Grav CMS. I only want to display the main content that comes after ===. What's the correct way to implement this?

Thank you in advance for your help!

2 years ago

I read this: Displaying page content without summary
My blog-item.html.twig code is now:

TWIG
<div class=“e-content>
        {% set content = page.content|slice(page.summary|length) %}
        {{ content|raw }}
</div>

But still the blog articles are displayed together with the “summary”.

2 years ago

Does page.summary return anything? Sounds like you don't have a summary 🤔

2 years ago

Summary works well in Blog List.
Cache is cleared regularly 🙂.

2 years ago

So what does page.summary|length say on the item page?

2 years ago

If you're talking about what's between the --- in the blog_item.en.md file, it looks like this:
summary: { }

2 years ago

That's the summary config, but what's the actual summary length?

2 years ago

Where exactly can I check the actual summary length? In which file or section should I look?
In /user/config/site.yaml it is written like this:

YAML
summary:
  enabled: true
  format: short
  size: 300
  delimiter: '==='
2 years ago

In blog-item.html.twig add:

TWIG
{{ dump(page.summary) }}
{{ dump(page.summary|length) }}

Or is it {% ... %} 🤔

2 years ago

Hi @Dima and @Karmalakas

I have just tested the recipe on my own installation and it works perfectly. Several things can happen here...

  • On the Blog page, where the entries are listed, a summary can be displayed even if it is not defined in your markdown file.
  • The code in blog-item.html.twig may be wrapped in a block that another file overwrites.
  • One other thing that escapes me 😅

I would make sure you have created the summary in the .md file and review the templates that are involved in the view. Surely the error must be in there!

2 years ago

Good question:) Gantry Helium. But the content is placed in “Page Content”.

2 years ago

Everything and it should work perfectly. But I'm trying to figure out what I'm doing wrong.

2 years ago

Yeah, that was right one 😁
Next, where exactly did you make your code modification?

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 7 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 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