FAQ
I'm executing a template with 2 parallel arrays (same size) and I want to
list items from both arrays in parallel, how do I use index inside of range?

this obviously doesn't work:

{{range $i, $e := .First}}$e - {{index .Second $i}}{{end}}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jesse McNelis at Apr 22, 2013 at 9:03 am

    On Mon, Apr 22, 2013 at 5:28 PM, wrote:

    I'm executing a template with 2 parallel arrays (same size) and I want to
    list items from both arrays in parallel, how do I use index inside of range?

    this obviously doesn't work:

    {{range $i, $e := .First}}$e - {{index .Second $i}}{{end}}
    In a 'range' dot is set to the value at the index in the ranged array.
    Thus your .Second refers to the 'Second' field of the $i'th element of
    .First.
    You probably want $.Second
    "When execution begins, $ is set to the data argument passed to Execute,
    that is, to the starting value of dot."

    eg.

    {{range $i, $e := .First}}$e - {{index $.Second $i}}{{end}}

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 22, '13 at 7:28a
activeApr 22, '13 at 9:03a
posts2
users2
websitegolang.org

2 users in discussion

Jesse McNelis: 1 post Gbenhaim: 1 post

People

Translate

site design / logo © 2023 Grokbase