# Email a table from PostreSQL data

**URL:** <https://discourse.nodered.org/t/email-a-table-from-postresql-data/39659>\
**Category:** General\
**Created:** [24 January 2021 17:19 UTC](https://discourse.nodered.org/t/email-a-table-from-postresql-data/39659 "2021-01-24T17:19:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndrePretorius](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@AndrePretorius](https://discourse.nodered.org/u/AndrePretorius)\
**Post date:** [24 January 2021 17:19 UTC](https://discourse.nodered.org/t/email-a-table-from-postresql-data/39659/1 "2021-01-24T17:19:51Z")

</div>

Hi There  
I am trying to send data from a PostgreSQL query via a HTML function through Email. The problem is to dynamically create the rows. Here is what i have so far in a standard template node.

Any advice would be appreciated

```auto
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<h2>Dayly Alarms</h2>

<table id="table" border="1">
     <tr>
    <th>created</th>
    <th>device_type</th>
    <th>ack_by</th>
    <th>Ack_time</th>
    <th>alarm_type</th>
    <th>device_imei</th>
    <th>device_id</th>
    <th>site</th>
 </tr>

  <tr ng-repeat="row in msg.payload">
    <td>{{payload[prop].created}}</td>
    <td>{{payload[prop].device_type}}</td>
    <td>{{payload[prop].ack_by}}</td>
    <td>{{payload[prop].Ack_time}}</td>
    <td>{{payload[prop].alarm_type}}</td>
    <td>{{payload[prop].device_imei}}</td>
    <td>{{payload[prop].device_id}}</td>
    <td>{{payload[prop].site}}</td>
  </tr>
  
</table>

</body>

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 January 2021 20:43 UTC](https://discourse.nodered.org/t/email-a-table-from-postresql-data/39659/2 "2021-01-24T20:43:28Z")

</div>

I think that is the ui template syntax

In the standard template use mustache syntax

```auto
[{"id":"be3f52ab.3c4e78","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"created\":\"1\",\"device_type\":\"2\",\"ack_by\":\"3\"},{\"created\":1,\"device_type\":2,\"ack_by\":3},{\"created\":1,\"device_type\":2,\"ack_by\":3}]","payloadType":"json","x":140,"y":2720,"wires":[["2a62bb62.f0f7cc"]]},{"id":"2a62bb62.f0f7cc","type":"template","z":"57675e72.26a0d8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n<style>\ntable, th, td {\n border: 1px solid black;\n}\n</style>\n\n\n\n<h2>Dayly Alarms</h2>\n\n<table id=\"table\" border=\"1\">\n <tr>\n <th>created</th>\n <th>device_type</th>\n <th>ack_by</th>\n </tr>\n {{#payload}}\n <tr>\n <td>{{created}}</td>\n <td>{{device_type}}</td>\n <td>{{ack_by}}</td>\n </tr>\n {{/payload}} \n</table>\n\n","output":"str","x":310,"y":2700,"wires":[["662e84ea.e38f1c"]]},{"id":"662e84ea.e38f1c","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":2700,"wires":[]}]

```

[http://mustache.github.io/mustache.5.html](http://mustache.github.io/mustache.5.html)

```auto
  {{#payload}}
  <tr>
    <td>{{created}}</td>
    <td>{{device_type}}</td>
    <td>{{ack_by}}</td>
  </tr>
    {{/payload}} 

```

---

<div class="post-metadata">

**Author:** ![AndrePretorius](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@AndrePretorius](https://discourse.nodered.org/u/AndrePretorius)\
**Post date:** [25 January 2021 15:26 UTC](https://discourse.nodered.org/t/email-a-table-from-postresql-data/39659/3 "2021-01-25T15:26:17Z")

</div>

Thanks, it seems to be working perfect

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 March 2021 15:27 UTC](https://discourse.nodered.org/t/email-a-table-from-postresql-data/39659/4 "2021-03-26T15:27:05Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
