1

I have a data structure that is sometihng like:

map[string]SomeStructure

I have another struct that encapsulates the above plus additional variables and other structs and that's what gets sent to the template:

type page struct {
    Status   map[string]SomeStructure
    Database  []string
}

In my template file I want to be able to do something like

{{ range index .Database}} 
    {{ .Status "KEY".MemberVariableOfSomeStructure }}
{{ end }}

Except I want the "KEY" to be dynamic based on the iterating .Database value.

1 Answer 1

3

You can use the index function to access a map.

{{ range .Database }} 
    {{ index $.Status . }}
{{ end }}

See play.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.