Questions tagged [go-html-template]

Relating to using the html/template package. This package is similar to the text/template package but has logic relating to html, url, and javascript escaping as well a generating html.

Relating to using the html/template package. This package is similar to the text/template package but has logic relating to html, url, and javascript escaping as well a generating html.

98 questions
2
votes
1 answer

How does text/template determine the "default textual representation" of a map?

Per the documentation of the text/template package in the Go standard library, (html/template would be the same here as far as I know) simply using the pipeline operator will spit out a "default textual representation" of whatever that…
Matt Mc
  • 8,882
  • 6
  • 53
  • 89
2
votes
1 answer

avoid auto escape in html template

Trying to render HTML template with an URL. The problem is that the URL contains () in it, and those characters are escaped. I tried to use template.URL("http://myurl.com/(data)/aaa.jpg") and also template.HTML("http://myurl.com/(data)/aaa.jpg") but…
Jérôme
  • 1,060
  • 1
  • 7
  • 18
2
votes
3 answers

css class based on loaded template

I've got this bootstrap nav in my _base.html template like this: Using Golang I want to add a class="active" to the corresponding…
Dani
  • 2,448
  • 8
  • 27
  • 44
1
vote
1 answer

Golang Fiber Render - Sending data to multiple Layouts

I'm trying to switch from PHP to GO, but I'm stuck at one point, I ask for your help. I linked navbar.html, which is where I will draw my menus and logo, into index.html. but I can't pull the data that I assigned for the index into the navbar from…
Ugur Tas
  • 216
  • 1
  • 9
1
vote
1 answer

Render table in html template where table-data are keys and values of some json data in Golang

In backend I send http request to some third party site and retrieve some json data in response. Keys in the json response are not always same, but I have some idea of what they might be. For example: Sending request to example.com/data/1 could…
1
vote
0 answers

Html template parse with sprig does not work in go

I am very new to golang and trying to use sprig package with html/template. I am converting the template to PDF. I get a blank response in postman when I use the below code(parseFiles). tempPath variable is just a string with the path to my html…
girish
  • 302
  • 1
  • 5
  • 17
1
vote
0 answers

How to read a new png file during run time and add to html template

I need to produce a table and graph (png image) both at runtime. I know that i can host the image somewhere or store it in blob storage and then add this url to an image tag, but we are already creating a html file and saving this to blob storage.…
1
vote
1 answer

How to inject Javascript in html template (html/template) with Golang?

Is there any way to inject Javascript as a variable in Golang html template (html/template). I was expecting the script to be injected in the template however script is injected as string inside ". template.html ... {{ .myScript…
Vhndaree
  • 594
  • 1
  • 6
  • 20
1
vote
1 answer

How can I pass a nested struct to a gohtml template file and display it in a table?

I can't figure out how to pass the data that I get from the MySQL database to my HTML template and display every column in a table. The Instructions I found work fine, however when i try to implement it into my own code it won't pass the data to my…
BumbleB-NL
  • 61
  • 6
1
vote
1 answer

Combine two ranges to give name and hyperlink

I am trying to create a hyperlink attached to a name, however both groups are in two separate ranges i.e. names are in one range and the links are in another. Is there a way to combine the two? Currently the html code I have is as below, however,…
Fazila
  • 55
  • 5
1
vote
1 answer

Using HTML Template with golang, how do I print index of the given data in the HTML?

i'm doing a school work, i need to do an Html Template using go, i give it a data fetched by the go, i want in the html if possible to print the first index (for testing it could be other index later) of the data (the data is All called by . in html…
1
vote
0 answers

html/template: Unescape a specific data-value in template

I am working on a template that is powered by Go's html/template package, and I have a specific string value that is passed into the template that needs to be unescaped. The one constraint is that I cannot render the entire template through…
Johnnie
  • 197
  • 1
  • 9
1
vote
0 answers

SOLVED: Pretty print JSON using Golang templates

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…
panic
  • 11
  • 4