Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Avoid extra paragraph and possibility to add classes to page.content

Solved by Vadym View solution

Started by Pedro M 4 years ago · 2 replies · 706 views
4 years ago

Hi.
I have this code in a template:

TWIG
<p class="excerpt">
    {{ page.content|raw }}
</p>

In the html output I get the following result:

HTML
<p class="excerpt">
<p>Content paragraph here...</p>
</p>

I'd like to get only one paragraph with its css classes (in this example "excerpt")

how can I get it?

Thanks.

4 years ago Solution

Hi @pmoreno
how about using a custom theme variable?
otherwise what you can try
1.use striptags twig filter

TWIG
<p class="excerpt">
    {{ page.content|striptags|raw }}
</p>

or

  1. disable markdown process for the entire page
    if there are no more markdown on the page
    set through admin panel or in page .md file
YAML
process:
    markdown: false
    twig: true
last edited 11/21/22 by Vadym
4 years ago

Thanks @b.da

It is a good solution if no html tag is included in the content. Otherwise another solution would be to wrap page.content in a div tag.

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 23 hours ago
2 40 16 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago