I need to pass data from the map[string]interface{} through the template
I dont know why, but I catch the error:
template: stone-card.html:2: function "stoneShop" not defined.
Code in go:
files := []string{
                dirWithHTML + "index.html",
                dirWithHTML + "stone-card.html",
            }
            tmp, err := template.ParseFiles(files...)
            if err != nil {
                fmt.Println(err)
            }
            err = tmp.Execute(w, block)
            if err != nil {
                log.Fatal(err)
            }
            stoneShop := stones()
            err = tmp.ExecuteTemplate(w, "stone", stoneShop)
            // var stoneShop map[string]interface{}
            if err != nil {
                log.Print(err)
            }
Template Code:
{{define "stone"}}
{{range $key, $value := stoneShop}}
<li class="card {{$value.Rare}}">
    <div class="side1">
      <img class="card__img" src={{$value.URL}} alt="{{$value.Name}}">
    </div>
    <div class="side2">
      <h3 class="card__name">
        {{$value.Name}}
      </h3>
      <p class="card__desc">
        {{$value.Description}}
      </p>
      <div class="card__rare">
        {{$value.Rare}}
      </div>
      <div class="buy">
        <button class="btn btn-reset">Купить</button>
        <div class="item-price">{{$value.Price}} C</div>
      </div>
    </div>
</li>
{{end}}
{{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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2edfe28a-d136-43a4-819e-081644d1683cn%40googlegroups.com.

Reply via email to