vinniyo
vinniyo

Reputation: 877

passing slices in a nested struct into Revel template in Go

I'm trying to pass off slices in a nested struct to a Revel template, but I get the error:

7: executing "App/Index.html" at <.data.company>: company is an unexported field of struct type interface {}

CONTROLLER
type company struct {
    Tradetotals float64
    Totals      float64
    CostCount   string
    TraderCount string
}

type alldata struct {
    company []company
}



func (c App) Index() revel.Result {
    //etc
    //etc
    //etc

    return c.Render(data)
}

INDEX
{{range $count, $company := .data.company}}
    <div>
    <button type="submit" class="btn btn-sq-lg btn-danger" name="333" value="2-50000">
            <i class="fa fa-user fa-5x"></i><br/>
            Demo Danger <br>Button
    </button>

          <button type="submit" class="btn btn-sq-lg btn-success">
            <i class="fa fa-user fa-5x"></i>
            US: {{$company.Tradetotals}}<br>{{$company.Totals}}<br>{{$company.Totals}} {{$company.CostCount}}

    </button>
    </div>
{{end}}

Does anyone know how to accomplish this? Any help would be appreciated! Thank you.

Upvotes: 0

Views: 327

Answers (1)

T. Claverie
T. Claverie

Reputation: 12256

There is a problem in your struct. When executing a template, you only have access to the exported fields of your structs.

If you try to access an unexported one, you'll receive an error. It should solve your issue.

type alldata struct {
    Company []company
}

Upvotes: 1

Related Questions