2 struct in 1 Slice/Array [Newbie]

Hey! I’m tring to build an some basic web app with Go. I’m executing the template with

t.Execute(w, someArray)

someArray has some type of struct. But now I need to pass more then 1 slice/array. I’m thinking about putting 2 array to array. But I could’nt done it. My brain probably died. While I’m writing that I understood thats a silly thing. How can I do that? Here is playground link:


Any is spelled interface{} in Go: https://play.golang.org/p/hgfazssiRbt

This is not usually something you want to do. In order to pass it to template processing it may be entirely appropriate, though.

This is not usually something you want to do.

What do you suggest? How can I pass two things? How would you do that?

You can pass struct with more fields, one of them your existing slice.


But how to access them from .html

Before I was just doing

{{ range . }}
{{ .Name }}
{{ end }}

I put 2 slice in interafaces. In go ofcourse I can do k[0] But I can’t do {{ range .[0] }} or {{ range k[0] }}

range .People

I was playing with @calmh ‘s code.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.