FAQ
Hello,

I have a template which I would like to use to populate City names within a
group of <div> such that I can increment each new field before the {{end}}

I am uncertain as to how to do this and have tried the {{ index $key,
$value := . }} format, but either I am not understanding it or it isn't
doing what I would like it to.

Here is my template https://play.golang.org/p/xHS4IYfuFw

I think what I'd like to do it something like {{ for i = 0; i < len(.); i++
}}

so I can get my $value to change for each loop within my divs . As I have
it now, the values are the same for each iteration in the range, which
makes sense. Can someone please explain what I am doing wrong?

Thanks,
Dave

--
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/d/optout.

Search Discussions

  • Matt Harden at Oct 31, 2015 at 2:24 am
    If a "range" action initializes a variable, the variable is set to the
    successive elements of the iteration. Also, a "range" may declare two
    variables, separated by a comma:

    range $index, $element := pipeline

    in which case $index and $element are set to the successive values of the
    array/slice index or map key and element, respectively. Note that if there
    is only one variable, it is assigned the element; this is opposite to the
    convention in Go range clauses.

    On Fri, Oct 30, 2015 at 2:34 PM Dave Rose wrote:

    Hello,

    I have a template which I would like to use to populate City names within
    a group of <div> such that I can increment each new field before the {{end}}

    I am uncertain as to how to do this and have tried the {{ index $key,
    $value := . }} format, but either I am not understanding it or it isn't
    doing what I would like it to.

    Here is my template https://play.golang.org/p/xHS4IYfuFw

    I think what I'd like to do it something like {{ for i = 0; i < len(.);
    i++ }}

    so I can get my $value to change for each loop within my divs . As I have
    it now, the values are the same for each iteration in the range, which
    makes sense. Can someone please explain what I am doing wrong?

    Thanks,
    Dave

    --
    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/d/optout.
    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 30, '15 at 9:34p
activeOct 31, '15 at 2:24a
posts2
users2
websitegolang.org

2 users in discussion

Matt Harden: 1 post Dave Rose: 1 post

People

Translate

site design / logo © 2023 Grokbase