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

Why doesn't template.ParseFiles() detect this error?

If I specify a non-existent template in my template file, the error is not detected by ParseFiles() but by ExecuteTemplate(). One would expect parsing to detect any missing templates. Detecting such errors during parsing could also lead to…
3
votes
1 answer

How to create a global variable and change in multiple places in golang html/template?

I am creating a variable in html/template and and changing the value based on a condition. But the scope of the value stays only inside the if condition: {{if .UserData}} {{$currentUserId := .UserData.UserId}} [Inside…
Dany
  • 2,692
  • 7
  • 44
  • 67
3
votes
2 answers

How to pass multiple objects to Go html template

Here are my array of objects, type PeopleCount []struct{ Name string Count int } type Consultation []struct{ Name string Opd_count int Opinion_count int Req_count int } How should I pass both the objects to html…
Priyanka
  • 232
  • 3
  • 12
3
votes
1 answer

Golang template global dot within a template that's given a value from range

My setup: base.tmpl {{define "base"}} ...basic hmtl boilerplate ...{{end}} {{define "post"}} {{.ID}} {{.Username}} etc... {{if $.User.Admin}} <...admin controls...> {{end}} {{end}} index.tmpl {{template "base" . }} {{define…
THUNDERGROOVE
  • 197
  • 1
  • 10
3
votes
2 answers

Why a un-closed html tag make the html template not rendering in go?

I come to a very bothering problem, And it took me about an hour to figure what cause the problem, but I don't know why: I am using html/template to rending a web page and the code is like this: t, _ :=…
armnotstrong
  • 8,605
  • 16
  • 65
  • 130
2
votes
1 answer

Golang Gorm Fiber - How can I send the name I defined as alias to my index template?

I'm trying to switch from PHP to GO, but I'm stuck at one point, I ask for your help. I just define an alias named "durums" in the query, there is no such named field in the database. how can I send the name I defined as alias to my index…
Ugur Tas
  • 216
  • 1
  • 9
2
votes
1 answer

Golang - Html Template : How do I create a Nav-item - Submenu? I couldn't find how to do it

I'm trying to switch from PHP to GO, but I'm stuck at one point, I ask for your help. I have a table called Menu in the database. Here, menuid equal to 0 becomes the main menu. Those not equal to 0 depend on the written menuid. I want to draw the…
Ugur Tas
  • 216
  • 1
  • 9
2
votes
0 answers

Getting ZgotmplZ when sending an email link rendered with html/template to a Slack channel

I' trying to generate a mailto link with an email address as link text has confirmed his email, which I want to send to a slack channel. But when I parse the template with the user_email, I am getting the…
PRATHEESH PC
  • 1,461
  • 1
  • 3
  • 15
2
votes
1 answer

golang html/template templates with same names in different directories

Question: How can I specify a specific template for a specific method (with different routes), if they are in different folders and named the same? Descript: I have two tables in Database, Users and Agency with different fields for example. For each…
2
votes
0 answers

How do I access a Dynamic Property in Hugo Template while using the site variables

I have maintained an authors.json file inside of the data folder in my Hugo setup which contains an object of author details which looks something like this { "john_doe":{ "name":"john_doe", "github":"john_doe", …
2
votes
1 answer

Why don't HTML templates that I have parsed work?

I parsed my template files to make it easier for me to work. I named them {{define "pagearea"}}. For example {{define "footer"}}. Folder layout footer.tmpl - footer area index.tmpl - my home page main.go - go code :) topheader.tmpl - part of top…
2
votes
1 answer

Or statement in golang templates in combination with gt/lt (greaterThan, lowerThan)

I'm trying out the golang templates but I have one problem which don't know how to fix. Single statements like below work good. {{ if gt .TotalPrice 0.0 }} But a statement like the one below {{ if or gt .TotalPrice 0.0 gt .TotalMinutes 0.0…
Richard Lindhout
  • 2,038
  • 2
  • 23
  • 38
2
votes
2 answers

Anonymous struct as pipeline in template

Is there a way to do the following in a html/template? {{template "mytemplate" struct{Foo1, Foo2 string}{"Bar1", "Bar2"}}} Actually in the template, like above. Not via a function registered in FuncMap which returns the struct. I tried it, but…
mori
  • 973
  • 10
  • 11
2
votes
3 answers

Dockerfile directory structure for Go Webapp

I'm developing a test hello app in Go, which will have access to a Postgres DB. This will use a statefulset to release in kubernetes and has one pod with two container images (one for pgsql & one for goapp). ├── hello-app | ├── templates | …
Tristan C
  • 119
  • 1
  • 11
2
votes
0 answers

Format GoLang HTML templates from command line?

To enforce a codestyle in a Go project, one can use the gofmt tool to format .go files, and make it part of the build chain. Is there any possibility to enforce proper formatting of Go template files (usually .html.tmpl extension—the gohtmltmpl…
Diti
  • 1,454
  • 3
  • 23
  • 38