Is there any way to print only selected paragraphs using {{ .Content }} ? I would like to print first paragraph on one div style, and print remaining paragraphs in the later div in different style.
Appreciate any suggestions or references ?
Is there any way to print only selected paragraphs using {{ .Content }} ? I would like to print first paragraph on one div style, and print remaining paragraphs in the later div in different style.
Appreciate any suggestions or references ?
You might have an easier time styling with CSS, and using :first or something:
Thanks for suggesting. But I still wonder how this works with hugo templates using .md content files.
Well .Content is a rendered string. Hugo has two regex functions replaceRe and findRe. I think you only need the latter for your use case.
I don’t have any implementation of this but by remembering similar ones I would say.
.Content in a variable you can work, say $content.findRe to find that first <p>anything</p> tag in .Content.{{ $first := findRE "{{<p>(.|\n)*?<\\p>" $content }}
You have that <p> tag and its content now at {{ $first = index $first 0 }} as findRe returns an array of strings.
$first from $content using replace
{{ $content = replace $content $first "" }}
$first wherever you like. and use $content as your new .Content.I did not test the above, especially the RegEx. You’re on your own for that set of trials an error 
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.