For loop in jog hogan template

I am using Express JS and the Jogan JS template engine. I know that hogan is a template with logic, but I need to execute a for loop in the form of code to create the table fields.

I did a lot of searches, but I did not find a solution. I know how to do if-else in Hogan JS.

I read all the documentation in the Hogan JS and Mustache JS websites.

I get values ​​in json format.

[
    {
        "email": "abc@example.com",
        "name": "abc",
        "date": "05/01/2015"
    },
    {
        "email": "xyz@example.com",
        "name": "xyz",
        "date": "05/01/2015"
    }
]

This is an example of json, there can be any amount of data. To show this data in a table, I have to repeat the loop. So I need for for-loop code.

+3
1

.

JSON .

var data = {"list" : [
   {
       "email": "abc@example.com",
       "name": "abc",
       "date": "05/01/2015"
   },
   {
       "email": "xyz@example.com",
       "name": "xyz",
       "date": "05/01/2015"
   }
]};  
var template = Hogan.compile("{{#list}} Your name is {{name}} and email is {{email}} <br/>{{/list}}"); 
var output = template.render(data); 

+4

Source: https://habr.com/ru/post/1607589/


All Articles