I have a partial that generates links to related pages in a website about a data model.
I have gotten it to return a link that looks right using printf:
{{- $whole_link := printf "<a href=\"/reference/classes/%s>%s</a>" $link $name -}}
Which displays in the browser as this:
<a href="/reference/classes/activity/>Activity</a>
whereas it should (of course) be the actual link to the Activity page.
I have the Goldmark renderer set up to deal with HTML, and I have tried using “safeHTML” everywhere I can think that it might go.
I technically have a working solution… because it works fine if I build it at the shortcode level one-link-at-a-time. At the moment the code that generates those links is reproduced in 3 places in the code, and I need it in four or five more cases, which makes it sort of beg for refactoring into a partial.
Current solution (this works):
{{- with $object -}}
{{ $lower := . | lower }}
{{- $link:= partial "retrieve_class_link" $lower -}}
{{- $name:= partial "retrieve_class_name" $lower -}}
<a href="/reference/classes/{{ $link }} "> {{ $name }}</a>
{{- end -}}
Desired solution (refactor):
{{- with $object -}}
{{- partial "class_link" . -}}
{{- end -}}
partial class_link.html:
{{ $lower := . | lower }}
{{- $link := partial "retrieve_class_link" $lower -}}
{{- $name := partial "retrieve_class_name" $lower -}}
{{- $whole_link := printf "<a href=\"/reference/classes/%s>%s</a>" $link $name -}}
{{- return $whole_link -}}
Can anybody tell me the missing piece?