[SOLVED] Insert something after the first paragraph of the content via template

Is there a way to insert an include to output something (like a text or js) after the first html paragraph of the content, using the template?

Thank you

So there is no solution to this? :pensive: I like Hugo very much, but without a way to insert a code programmatically after the first paragraph of a post I can’t convert my website.

A shortcode might help.

You would manually insert the shortcode at the appropriate place in each page.

Currently not.

But there are some similar issues:

1 Like

Thank you very much. I think I’ll go with the shortcode solution, even if it’s not the ideal solution (I have to edit all the posts and if I want to change something I have to edit them again).

It would be very userful to manipulate the text structure in such a way, I hope it will be possible in a near future.

After some thinking I found a solution. I share it here just in case anyone is facing the same problem.

Instead of using {{ .Content }} you can use:

{{ range $index, $element := split .Content "</p>" }}
        {{ $element | safeHTML }}</p>
        {{ if eq $index 0 }}
        {{ end }}
{{ end }}

I tried another solution with regex, but this one is better because you can place any text/code after any number of paragraphs.


2 posts were split to a new topic: Insert text after first paragraph

A post was split to a new topic: Insert a table of contents partial