Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

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 · 508 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 jean-louis67, 3 weeks ago
2 311 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 312 3 weeks ago
General · by Veehem, 4 weeks ago
0 264 4 weeks ago
General · by milkboy, 4 weeks ago
0 267 4 weeks ago
General · by ian russell, 1 month ago
2 336 1 month ago