tags:

views:

36

answers:

1

Say i have a data structure like this:

type Foo struct {
  Bar []struct {
    FooBar string
  }
}

And i fill it such that Bar has 3 elements. Now, using the template library, how can i access say the 3rd element's FooBar in that slice? I have tried the following with no success:

{Foo.Bar[2].FooBar}
{Foo.Bar.2.FooBar}

Now, i know that i can use {.repeated section Foo.Bar} {FooBar} {.end}, but that gives me the value of foobar for each element, rather than just a specific one. I have googled and asked on irc to no avail...

+1  A: 

I'm fairly certain this just isn't possible. Perhaps there's a way you could restructure your data so that it's all named fields.

Or just write some more logic in your actual application. Array indexing is somewhat beyond the scope of the template package I would think.

cthom06
That is what i did, but it was a lot more work than just using the indexes in the template file. Ah well...
crazy2be