gobeegogo-templates

Beego template value range executing "content" not a field of struct type


In my controller I set the following data:

c.Data["foos"] = foos

and

c.Data["user"] = user

So if I ask some property from user in the view, all fine.

{{if .user.IsSuperUser}}
    <th>ID</th>
    <th>Username</th>
{{end}}

But in:

<tbody>
{{range $foo := .foos}}
   <tr>
   {{if .user.IsSuperUser}}
      <td>xyz</td>
      <td>abc</td>
   {{end}}
...

myBeego:template: foo/foos.tpl:56:46: executing "content" at <.user.IsSuperUser>: user is not a field of struct type *models.Foo

How can I handle that?


Solution

  • I found this nice little link: In a template how do you access an outer scope while inside of a "with" or "range" scope?

    {{with .Inner}}
      Outer: {{$.OuterValue}}
      Inner: {{.InnerValue}}
    {{end}}