replaceRe more than once on .Content

My single.html looks like this

{{ define "main" }}

  <h1>{{ .Title }}</h1>

  {{ .Content }}

{{ end }}

Let’s say I want to replace something with Regex and the replaceRe function is defined in a partial called regex1.html then this works:

{{ define "main" }}

  <h1>{{ .Title }}</h1>

  {{ partial "regex1.html" .Content }}

{{ end }}

Let’s say there is another Regex I want to apply on the .Content. Then something like that

{{ define "main" }}

  <h1>{{ .Title }}</h1>

  {{ partial "regex1.html" .Content }}
  {{ partial "regex2.html" .Content }}

{{ end }}

prints the .Content two times. How to print the .Content only one time after applying first regex1 than regex2 on the whole content?

single.html

{{ $foo := partial "regex1.html" .Content }}
{{ $bar := partial "regex2.html" $foo }}
{{ $bar }}

regex1.html

{{ $content := . }}
{{ $content = ... }}
{{ return $content }}

regex2.html

{{ $content := . }}
{{ $content = ... }}
{{ return $content }}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.