Display page.content without page.summary

Hi,

displaying post or page content without the page summary has popped up a couple of times around here (for example: Content without summary), and most answers loop back to the same answer https://learn.getgrav.org/16/cookbook/twig-recipes#displaying-page-content-without-summary suggesting this solution:

{% set content = page.content|slice(page.summary|length) %}

However, this does only work for cases where the summary is of a set (standard) length, and is not accounting for use of the “===” summary delimiter.

In my case, summaries will be of unknown (and varying) length, yet the contents excluding the summary need be displayed at one point on the page.

Any suggestions how to achieve this? I’m guessing I’ll need a custom plugin?

Hi @smiletolerantly, I use the above technique and it does work with the === delimiter to support variable length. You can see it in action with my Open Course Hub skeleton (which uses the Bootstrap4 Open Matter theme (https://github.com/hibbitts-design/grav-theme-bootstrap4-open-matter/blob/master/templates/partials/blog_item.html.twig#L145).

1 Like

Oh. Previously I was under the impression that I should be able to abbreviate

{% set content = page.content|slice(page.summary|length) %}
{{ content }}

with

{{ page.content|slice(page.summary|length) }}

Looks like I was wrong though - the (longer/complete) solution does indeed work.

(Am I missing something fundamental here…? Why IS the “abbreviation” not working?)

1 Like

Not sure if that abbreviation is supported… I’ve only used the initial version. Glad to hear you got things going!

1 Like

Hi,

According to the documentation, the one line version should work either.

{{ '12345'|slice(1, 2) }}
{# outputs 23 #}

You can use any valid expression for both the start and the length:
slice(start, length)
If length is omitted, then the sequence will have everything from offset up until the end of the variable.

So…

{{ page.content|slice(page.summary|length) }}

…should do the job. And after a test, it does :slight_smile:
This code give me twice the page content without the summary:

{{ page.content|slice(page.summary|length) }}
<hr/>
{% set content = page.content|slice(page.summary|length) %}
{{ content }} 

The one line version produce exactly the same output than the 2 lines version.