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.

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 · 351 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 Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago