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.

Themes & Styling

Customizing Blog Post Layout Using "Summary Size and Separator"

theme

Started by Norbert 2 years ago · 11 replies · 447 views
2 years ago

I'm working on a blog in GRAV CMS and aiming for a specific layout for my blog posts. I plan to include a header, an introductory paragraph, followed by the first image in the folder, and then the rest of the content. I've tried using the following code to manipulate the layout:

TWIG
{{ page.summary|raw }}
<img ... />
{{ page.content|raw }}

However, this results in the text summary appearing both above and below the image within the full text block. Is there a way to configure the "Summary Size and Separator" or adjust my code to display the first paragraph above the first image from the folder, without repeating the summary text?

2 years ago

I will not have added summary text for every entry.

In this case, with the standard configuration:

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

and the code in the template:

TWIG
{{ page.summary|raw }}
<img ... />
{{ page.content|slice(page.summary|length)|bettertypo()|raw }}

breaks the text into two parts.

Simple check

TWIG
{% if page.summary %}
   {{ page.content|slice(page.summary|length)|bettertypo()|raw }}
{% else %}
   {{ page.content|bettertypo()|raw }}
{% endif %}

does not work because the property contains a trimmed string of characters and the condition is always true.

I would like to avoid adding specific properties in page.header and only use standard capabilities.

2 years ago

What's the "trimmed string of characters"?

2 years ago

If there is === in the page file, everything works and page.summary contains text with "===" above it.

HTML
Text summary
<img ... />
Text

However, if there is no === in the file, page.summary is not empty but contains a string of characters from the beginning trimmed to the value from the configuration file:

YAML
summary:
   size: 300

For this second example, I would like the content to look like this:

HTML
<img ... />
Text

not:

HTML
Text trimmed to 300 characters...
<img />
text from 300 characters to the end.
last edited 05/11/24 by Norbert
2 years ago

But by defining

YAML
summary:
   size: 300

You're explicitly telling Grav that this page has a summary of 300 chars, aren't you? If you remove that and there's no === in the content, then there's no summary and it should work as expected

2 years ago

I removed it and now the configuration looks like this:

YAML
summary:
  enabled: true
  format: short
  delimiter: '==='

However, it still creates a summary from the 300 character main text if there is no === in the text, which results in:

HTML
Text trimmed to 300 characters...
<img />
text from 300 characters to the end.
2 years ago

You're still explicitly saying that the page has summary

2 years ago

@q3d, Have you had a chance to read the docs about the summary?

By default, this value is 300 characters.

2 years ago

Maybe I'll ask in a different way. Is it possible to configure it so that in the absence of ===
page.summary() returned false or empty string?

However, if it is, return all the contents before ===.

2 years ago

Did you try

YAML
summary:
  enabled: false

? At least based on the docs, it should disable summary if there's no ===

3 months ago

Hey @q3d, bumping this because thanks to @paulhibbitts we have a solution.

@b.da:
Great snippet for splitting page content.

Headed in this direction in my project, but ended up with a custom variable as a simpler solution. Feel free to mark as solved if it’s what you were looking for.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 192 2 months ago
Themes & Styling · by Ian, 2 months ago
3 89 2 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 42 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 122 3 months ago
Themes & Styling · by Baphijmm, 4 months ago
4 78 4 months ago