Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

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 · 546 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 jeremycherfas, 1 week ago
5 195 2 hours ago
General · by lynbor, 6 days ago
2 129 3 days ago
General · by Old Man Umby, 1 week ago
1 103 1 week ago
General · by Sebastian, 2 weeks ago
1 128 2 weeks ago
General · by Andy Miller, 3 weeks ago
0 251 3 weeks ago