So I’ve been learning a lot about hugo and how to do stuff, and as my earlier posts have stated, I am trying to generate pages based on json. With all the help so farr I am making great progress, but yesterday I bumped into the next challenge to which I don’t know the answer (or whether its even possible to begin with). Note that everything I am doing here, is through templates.
Important edit: I initially hypothesized using .Inner in a partial might be better, but it turns out to be impossible, so I removed it from this post. Apologies for implying something is possible that isn’t.
Is it possible to use the rendering engine of hugo on bits of text without having to create markdown for it? To clarify:
One of the elements in my json file contains a string of text that I would like to present as a code block. The way I implemented it now is as followed:
{{ if .docString}}
<div class="docString">
{{ delimit (slice "```" .docString.mediaType "\n" .docString.content "\n```") "" | markdownify }}
</div>
{{end}}
Which is very ugly, but gets the job done. since I am working within templates, I can’t just do this:
{{ if .docString}}
<div class="docString">
```{{docString.mediaType}}
.docString.content
```
</div>
{{end}}
Because text in templates isn’t considered markdown. Preferably I want to bypass having to use markdown entirely and just go straight to the logic that generates the result and feed whatever it needs directly into it, something like:
{{partial "codeblock" .docString.mediaType .docString.content}}
At it’s core, I’m trying to avoid having to reinvent the wheel. Some very smart folks already built a way to present some text as a codeblock, so I just want to use whatever they have built. Not just because its less code to maintain, but also because that way I know whatever I am generating will be properly understood by the template I am using.