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.

Content & Markdown

Display page.content without page.summary

Solved by Paul Hibbitts View solution

Started by Charlotte 6 years ago · 4 replies · 1719 views
6 years ago

Hi,

displaying post or page content without the page summary has popped up a couple of times around here (for example: /forum/archive/content-without-summary-t3240), 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:

TWIG
{% 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?

6 years ago

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

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

with

TWIG
{{ 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
6 years ago

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

👍 1
6 years ago

Hi,

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

TWIG
{{ '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...

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

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

TWIG
{{ 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.

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 99 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 186 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 148 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 62 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 257 1 year ago