1

I am making a website using go templates. I need to print a variable containing JSON data to the screen. I'd like to pretty print it to the screen and haven't had any luck with that.

In flask I am able to do the following to accomplish this decently well:

{% autoescape false %} {{stringwithjsondata | safe | replace(",", "<br>")}} {% endautoescape %}

and was wondering if I could do something similar here.

I'm using the html/template package for the website.

EDIT: I over complicated this to eternity, I just used <pre> tags in the end with strings.replace to make it look good

panic
  • 11
  • 4
  • You can do pretty much anything, just write a function to format it how you want. See https://golang.org/pkg/html/template/#Template.Funcs and https://golang.org/pkg/text/template/#example_Template_func – Adrian Jun 15 '20 at 14:18
  • You can use something like the sprig library: https://github.com/Masterminds/sprig – Burak Serdar Jun 15 '20 at 14:44

0 Answers0