Joker / jade

Jade.go - pug template engine for Go (golang)
BSD 3-Clause "New" or "Revised" License
354 stars 37 forks source link

How iterate map? #51

Open WarL0ckNet opened 1 year ago

WarL0ckNet commented 1 year ago

In https://pugjs.org/language/iteration.html

ul
  each val, key in {1: 'one', 2: 'two', 3: 'three'}
    li= key + ': ' + val

How this write in your engine?

And how write one item from map? Example .arr[.key].field

arr{
  "one": {
     "field": 1
   },
   "two::{
      "field": 3
    }
}
UnrealView commented 1 year ago

Hello @WarL0ckNet, you can check the folder testdata/v2. There is a file about the iteration feature. In iteration.pug:

ul
  each val, index in map[int]string{1:"one",2:"two",3:"three"}
    li= strconv.Itoa(index) + ": " + val

For how write one item from map? You can try something with un/buffered code feature:

-
    var mymap = map[string]string{"one":"","two":"","three":""}

doctype 5
html
    body
        p= mymap["one"]