1

I would like to use a js variable in a go block within a template. Here is where i set the variable :

{{ range $tourneyNo, $tourney := . }}
    <ul><strong>Numéro du tournoi : {{ $tourneyNo }}</strong>:</ul>
    <script type="text/javascript">
        var $selectedTourney = {{ $tourneyNo }}; // set $selectedTourney = the last $tourneyNo --let's say it is 209
    </script>
{{ end }}

And here is how i would like to use it :

{{ with index . $selectedTourney}} // $selectedTourney should be replaced in the code by 209, as set before
    {{.Name }}
{{ end }}

The second part of the code is not working ; i want to get the element from . having the index defined previously in the $selectedTourney variable.

The goal intended is that a list of tourneys is displayed, the user clicks on one of theses tourneys and the info about this tourney is displayed, using js, down on the same page.

Thanks a lot for the help :D

Ezechiel
  • 69
  • 6
  • 3
    Related or duplicate: [Referencing go array in javascript](http://stackoverflow.com/questions/28751637/referencing-go-array-in-javascript) – icza Mar 16 '15 at 15:12
  • 3
    Please read the linked question _and_ the answers. – icza Mar 16 '15 at 15:37
  • Great, thanks a lot (edit : i went through the answers and only seen the solution on second reading ;p) – Ezechiel Mar 16 '15 at 15:38

0 Answers0