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
0
votes
1 answer

Can't get data from field in gohtml file

I'm trying to build a very basic page that takes user input from a form and displays it within an html template Here's the code that should take the input data from a form and make it available as a variable in the template. The input is printed to…
0
votes
1 answer

Unit test for html/template golang facing invalid memory address error

So I have a simple application that is supposed to render an Html page on GET requests /login/. The requests work fine when I run the web server locally, but when I run unit tests there seems to be an error.(go test -v is being used to run the…
aDev
  • 43
  • 9
0
votes
1 answer

How to iterate over []map[string]interface{} in Go to generate html table

Am trying to generate a HTML content using html/template in Go . The data is actually an output of SELECT query from different MySQL Tables. I need help on the below Am able to generate the HTML but am unable to split the rows. How to iterate over…
Gopi Kumar
  • 53
  • 5
0
votes
0 answers

Golang: Automatic whitespace/newline trimming by html/template library

So, I'm building my first web app, it is basically just word to an ASCII-ART converter. I started with simple displaying of my ascii-art result to the html page by standard html/template library. However, I ran into a problem that my strings are not…
Soncii
  • 11
0
votes
1 answer

Is there a way to display a field of a map[key-string] with value-struct, in html, in golang?

I have a datatype of map[key-string] value-struct, and I'm trying to display a field(Timing) of the struct I tried all sort of variations for an hour, can't seem to figure it out. Would appreciate any guidance on this, thank you! Also apologies on…
narwhal06
  • 13
  • 3
0
votes
1 answer

How do I make sure in JavaScript that when I click on any checkbox, the input field goes to 0

How do I make sure that when I click on any checkbox, the input field goes to 0. Because now it works with the first, but not with the others. This is the code I have now: let checkbox = document.getElementById("abs"); let inp =…
Justin S
  • 11
  • 4
0
votes
1 answer

How do I make sure with JavaScript that when I click on the checkbox, the input field gets the number 0?

This is the gohtml code containing the checkbox and the input fields with id="number" How do I ensure with JavaScript that when the checkbox is clicked, all the input fields are automatically entered with the number 0? The problem is that the 0 is…
Justin S
  • 11
  • 4
0
votes
1 answer

Looping through array elements in GoLang in the html/template

I have a Go web server where I would like to display the contents of a JSON file.. The main.go reads the file and puts the data into a struct. When I loop through the data in the struct directly, I can print the data in the terminal like this: Group…
Jason
  • 13
  • 3
0
votes
1 answer

What's the easiest way to define a custom HTML-stringification?

Is there a way for me to define that when I just output a value in Go html templates the way the formatting is done instead of it printing a string representation without having to call a function to explicitcly convert it? For example, let's say I…
Jimmy R.T.
  • 1,314
  • 1
  • 10
  • 13
0
votes
1 answer

Dynamic fields with Go html template

Can I make a html template in go work with dynamic properties? Like this for example currently results in the error Invalid template: template: sticker.CellRepresentation:1:23: executing "sticker.CellRepresentation" at <.sticker_set.url>: can't…
Jimmy T.
  • 4,033
  • 2
  • 22
  • 38
0
votes
1 answer

How can I use multiple html templates (ie. have a base template or footer template) in Go?

I am new to Go and am designing a website using Go. I wish to use multiple templates, such as a base template to incorporate with other templates , such as index. I would like to all the template parsing when the app first starts up. At the moment ,…
buckc
  • 31
  • 2
  • 6
0
votes
1 answer

How to access an element of a struct which is inside a struct of slice in gohtml?

I have a struct A with a slice B of struct C and other datatype. I am passing it to the gohtml template. How can I access the elements of struct C in gohtml template. type Str1 struct{ var_x string var_y string } type Str2 struct { …
0
votes
0 answers

Displaying/Extracting Table Data

I plan on building a very simple webapp on Go using it's html/template module for the front end. One typical function for the app is as follows: Get some data from external app Display that data in a table in one of the Go templates Permit the…
0
votes
1 answer

Why aren't the passed variables rendering in html/template?

I can't figure out why the passed variables aren't rendered with html/template This is what is rendered in the Browser: This is all the passed variables: [0xc0000a8ec0 0xc0000a8f80 0xc0000a9040 0xc0000a9100] City Population State Country…
0
votes
1 answer

How can I inject a if statement in an HTML attribute?

I'm trying to create a go html (Go 1.13) with a context {{.}}. I've managed to display context variables as div values, but I can't find the right way to put context variables inside HTML attributes. For instance, this code works: {{ if…