0

I want to render 2 different data(startup, event in this case) at the same time into html using golangs' html/template.

var startupData []model.StartupModel
err = startupCollection.Find(nil).Sort("-timestamp").All(&startupData )

var eventData []model.EventModel
err = eventCollection.Find(nil).Sort("-timestamp").All(&eventData )

How can I combine both startupData and EventData into a variable so that I can render as the following ?

    t.Execute(w, result) // result is eventData + startupData

1 Answers1

0

You can create a struct and pass to Execute function

...
result := struct {
        StartupData []model.StartupModel
        EventData []model.EventModel
    }{
        StartupData : startupData,
        EventData : eventData,
    }
t.Execute(w, result)
Tinwor
  • 7,765
  • 6
  • 35
  • 56