go-templates Questions

1

Solved

I 'm new to go and I got my mind stuck with something pretty trivial, so I ask for your help, maybe anyone knows why this behaviour happens: I want to output the query params string of an url obje...
Pharisaism asked 28/6, 2017 at 10:34

1

Solved

In the data I pass to my template I have the two variables Type and Res.Type I want to compare to preselect an option for my select field. To illustrate my problem I have created this simplified v...
Alvardo asked 24/6, 2017 at 8:34

2

Solved

I have simple case, where a templates (text/templates) includes another like this `index.html` {{ template "image_row" . }} `image_row.html` {{ define "image_row" }} To stuff here {{ ...
Iodism asked 15/4, 2017 at 12:25

2

Solved

Similar question answered here, but I don't think it solves my problem. Let's say you have the following struct: type User struct { Username string Password []byte Email string ... } Moreov...
Volvox asked 6/4, 2017 at 18:38

1

Solved

I have a Golang template, defined like this {{- define "test" -}} {{- printf "%s" .Name | trunc 24 -}} {{- end -}} Then I use it in one of my files: {{ template "test" . }} What does the dot ...
Infrequent asked 28/2, 2017 at 11:47

4

Solved

My Problem is that, I want to build a letter generator, which first builds a latex-file from user input, and then compiles this via latex to PDF. The template contains multiple lines like this: \...
Grin asked 23/5, 2013 at 7:3

3

Solved

I'm new to using Hugo and Go Templates. How can I access a variable from a partial file that is defined in base file using Hugo? For eg: I have an index.html file which contains code that reads th...

2

Solved

In my go code I often use if like this if user && user.Registered { } equivalent code in go templates would be {{ if and .User .User.Registered }} {{ end }} Unfortunately code in the ...
Troublesome asked 13/2, 2017 at 16:5

2

Solved

Is there a simple way like template.ParseFiles("base.html", "home.html") but for strings to build a template from a set of strings? I have a base template and a list of pages templates (all as str...
Holyhead asked 25/1, 2017 at 15:55

1

Solved

I use "text/template" module. I have struct like this to parse XML from Blogger type Media struct { ThumbnailUrl string `xml:"url,attr"` } type Entry struct { ID string `xml:"id"` Published ...
Shaniceshanie asked 14/1, 2017 at 7:33

2

Solved

I'm trying to do some simple work with the text/template package. The sample given at the top of template is what I'm working with. How do I write the 'parsed' file so template.ParseFiles() proper...
Drew asked 4/8, 2012 at 2:4

1

Solved

In golang's template/html package, I can use {{ if .loggedIn }} to check if logged in is true. How do I check if .loggedIn is false without using ne or eq? For example, I am looking for somethi...
Bourassa asked 22/12, 2016 at 14:56

1

Within a template, how can I achieve this? {{$var := template "my-template"}} I just get "unexpected <template> in operand".
Cant asked 20/10, 2016 at 21:31

2

Solved

Given this Go text/template code: Let's say: {{ if eq .Foo "foo" }} Hello, StackOverflow! {{ else if eq .Foo "bar" }} Hello, World! {{ end }} We get the following output in case Foo equals "foo"...
Forgather asked 9/10, 2016 at 20:48

4

Solved

I’m using AngularJS as the front-end JS library, with Go templates within Revel framework to to generate the markup on the back-end. But both Go and Angular use {{ and }} for delimiters in their t...
Socorrosocotra asked 14/7, 2013 at 17:37

2

Solved

I have stored some content in MySQL that looks like this. "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.google.com" When I print it in Golang template, its not parsing corr...
Lieutenancy asked 6/8, 2016 at 12:26

1

Solved

I'm looking for a way of binding json data directly into a template (without any struct representation in golang) - and I'm coming up short. Essentially, what I want is to have both template docume...
Torosian asked 18/7, 2016 at 12:35

1

Solved

How to access range within range in Go templates? Template: {{range .Resume.Skills}} {{.Name}} {{.Level}} {{range $item, $key := .Keywords}} {{$key}} {{$item}} {{end}} {{end}} Struct: t...
Orthopter asked 4/7, 2016 at 18:41

1

Solved

I have a simple Go / Gin web app. I need to put some dynamic content in html template. For e.g. I have a few tables (the number is dynamic) with a few rows (the number is dynamic). I need to put t...
Vahe asked 14/6, 2016 at 13:11

1

Solved

How can I conditionally display something else if my range is empty? {{range .Users}} ... {{end}} If the range is empty, I want to display a different block of HTML.
Dunsinane asked 28/5, 2016 at 22:59

1

Solved

I have Files slice of File structure in my Go program to keep name and size of files. I created template, see below: type File struct { FileName string FileSize int64 } var Files []File const tm...
Bello asked 9/5, 2016 at 19:48

1

Solved

Basic information Go version: go1.4.2 darwin/amd64 Operating System: Mac OS X 10.10.5 I'm working on a small Web project written based on go and gin. Here is my golang code. After running go ru...
Romanist asked 14/8, 2015 at 8:21

1

Solved

Inside a golang template when simply outputting values it seems that pointers are automatically dereferenced. When .ID is a pointer to an int, {{.ID}} outputs 5 But when I try to use it in a pipe...
Nan asked 24/2, 2016 at 18:15

2

Solved

I am unable to find any documentation regarding what the type of the return value is when attempting key into a map in which the key doesn't exist. From the Go bug tracker it appears to be a specia...
Spermiogenesis asked 21/1, 2016 at 6:49

1

Solved

Is it possible to check if a struct field exists from within a Go HTML template? For example, given the following template: {{if .FieldA}} <a>{{.FieldA}}</a> {{end} and structs de...
Shari asked 10/1, 2016 at 7:29

© 2022 - 2024 — McMap. All rights reserved.