The price field is under .USD.price (function node) or in the template using .price.īelow is a screen shot of the template node. The name field is directly under data and is accessed using the code (function node) or in the template using. ![]() This is what the data looks like and I have marked the data that I am interested in. I am only interested in the data object which is an array with 2 elements.īecause the data object is quite complex I have pulled the data into the online JSON viewer. You should note that the msg.payload consists of two objects. If I look at the data coming in in the node-red debug node I see this: Note : i have made no attempt to line up the header as it is a demo only. I have thinned down the original list just to two cryptos to make it easier to demonstrate. This data is taken from coinmonitor via a rest API. This is shown below for all three elements: Remember the array enters the template as payload and so the first element is payload.0 In the array example we used the loop construct we could access each element of the array using the array index. To print each value of the array in a table use: ![]() To use an array that contains simple values you can reference each value using the. Using objects in Mustache templates is probably the easiest. Notice each array element is an object and I have shown the contents of the first array element in the screen shot below. Inside the for loop we create table elements and insert data using this code. The example given in the documentation is a template containing the following: This is the payload: It can be used for dynamically inserting data into a page using Mustache templates which is the default configuration. Generally the template node is used for creating web pages and so generally contains contains HTML mark-up. If the template contains JSON data or YAML data which is common when using the template as a configuraiton node you can output the data as a parsed JSON object or parsed YAML object i.e JavaScript. ![]() You can even send it directly to a flow or global variable. Normally this is msg.payload but you can change it to anything you want. The field called property sets the name of the output object from the node. The node accepts input in the msg.payload object The properties of the template node are shown below. In this tutorial we will discuss the HTML template node which is a core node, and is located in the function section. They are the HTML template node and the dashboard template node. There are two template nodes in node-red.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |