Skip to content
Jair Andres Diaz Puentes edited this page Mar 15, 2018 · 2 revisions

loop

Use #each to iterate through items

var template = {
  "orders": {
    "{{#each customers}}": {
      "order": "One {{menu}} for {{name}}!"
    }
  }
}

var data = {
  "customers": [{
    "name": "Hatter",
    "menu": "miso ramen"
  }, {
    "name": "March Hare",
    "menu": "tonkotsu ramen"
  }, {
    "name": "Dormouse",
    "menu": "miso ramen"
  }, {
    "name": "Alice",
    "menu": "cup noodles"
  }]
}

Select and transform

ST.select(template)
    .transform(data)
    .root();

Get the result

{
  "orders": [{
    "order": "One miso ramen for Hatter!"
  }, {
    "order": "One tonkotsu ramen for March Hare!"
  }, {
    "order": "One miso ramen for Dormouse!"
  }, {
    "order": "One cup noodles for Alice!"
  }]
}
Clone this wiki locally