# Show a simple text file as a list with dashboard 'template'

**URL:** <https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842>\
**Category:** General\
**Tags:** dashboard\
**Created:** [15 July 2023 11:28 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842 "2023-07-15T11:28:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [15 July 2023 11:28 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/1 "2023-07-15T11:28:36Z")

</div>

A simple task for NR/ui\_template, but the solution is not obvious to me!?  
A text file is to be read and displayed as a list on a dashboard with ui\_template.  
The list is stored on a RPI and is read by NR ('read file') and converted to an object with '(msg.payload).split("\n")'.  
However, in the subsequent 'template' with ng-repeat, the list is not generated as expected!?

Here is the flow:  
 ![flow_testfile](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c3c53ebbce38148144bea8d1e3f68c9944c4c86.png)  
[flow\_testfile.png.json](https://discourse.nodered.org/uploads/short-url/ambuKfv9c6KFsA3x00G2w0hpBnX.json) (6.6 KB)

_The main code part is this:_ (in 'Function List testing')

```auto
let msg1 = null; // INI1 part: test string 
let ini1 = ["Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7"];

let ptype1 = [typeof ini1] 
msg1 = {
        payload: ini1
}

let msg2 = null; // INI 2 part: handling the test.txt file / object
let ini2 = (msg.payload).split("\n");
let ptype2 = [typeof ini2] 
msg2 = {
        payload: ini2
}

let msg3 = null; // just check the type together with test text  
msg3 = {
        payload: [ini2, ptype2]
}

return [msg1, msg2, msg3];

```

The generated screen:

 ![flow_testfile_UI](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6ee16da33c33057d9daea94edd074896881d5f54.png)

And Debug Listings with //comments:

```auto
  node: debug test.txt // read test file
msg.payload : string[118]
"Zeile 1↵ Zeile 2, 11, 22, 33↵ Zeile 3↵ Zeile 4, 111, 222, 333, 444↵ Zeile 5, 5, 55, 555, 5555↵Zeile 6, 66↵Zeile 7, 7↵↵"

  node: debug fct 1 // an example string handled in a separate template  
msg.payload : array[7]
["Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7"]

  node: debug fct 2 // test file converted to object
msg.payload : array[9]
["Zeile 1", " Zeile 2, 11, 22, 33", " Zeile 3", " Zeile 4, 111, 222, 333, 444", " Zeile 5, 5, 55, 555, 5555", "Zeile 6, 66", "Zeile 7, 7", "", ""]

  node: debug ini 1 // example string converted to object
msg.payload : array[7]
["Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7"]

  node: debug ini 2 // output/passthru of 'template'
msg.payload : array[9]
["Zeile 1", " Zeile 2, 11, 22, 33", " Zeile 3", " Zeile 4, 111, 222, 333, 444", " Zeile 5, 5, 55, 555, 5555", "Zeile 6, 66", "Zeile 7, 7", "", ""]

```

* * *
Who can shed some light on this? Any help / explanation is greatly appreciated

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 July 2023 15:12 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/2 "2023-07-15T15:12:17Z")

</div>

So it looks like the text data coming in has a bunch of `"↵"` in it. You need to convert them to separate lines and remove the last two lines.

Try this as the function:

```auto
// 2023-07-15_11

let msg1 = null;
let ini1 = ["Zeile 1a", "Zeile 2, 11, 22, 33", "Zeile 3", "Zeile 4, 111, 222, 333, 444", "Zeile 5", "Zeile 6", "Zeile 7"];

let ptype1 = [typeof ini1] 
msg1 = {
        payload: ini1
}

let msg2 = null;
node.warn(msg.payload)
let m = msg.payload
m = m.replace("↵↵","")
let ini2 = m.split("↵");
node.warn(ini2)
let ptype2 = [typeof ini2] 
node.warn(ptype2)

msg2 = {
        payload: ini2
}

let msg3 = null;
msg3 = {
        payload: [ini2, ptype2]
}

return [msg1, msg2, msg3];

```

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [15 July 2023 15:22 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/3 "2023-07-15T15:22:19Z")

</div>

The file I use is basically the same "string" as with the one node (see last array[9] above).  
But here is a dump on the RPI/ssh:

```auto
~/schedulePlus/data $ cat test.txt
Zeile 1
 Zeile 2, 11, 22, 33
 Zeile 3
 Zeile 4, 111, 222, 333, 444
 Zeile 5, 5, 55, 555, 5555
Zeile 6, 66
Zeile 7, 7

```

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [15 July 2023 15:30 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/4 "2023-07-15T15:30:28Z")

</div>

If I change

> [@gNeandr](#):
>
> ```auto
> msg2 = {
> payload: ini2
> }
> 
> ```

to this:

```auto
msg2 = {
        payload: [ini2]
}

```

for the "Listing INI 2" it generates one line with

```auto
* ["Zeile 1"," Zeile 2, 11, 22, 33"," Zeile 3"," Zeile 4, 111, 222, 333, 444"," Zeile 5, 5, 55, 555, 5555","Zeile 6, 66","Zeile 7, 7","",""]

```

but it's not resolving like with the first "test.txt" string in "Listing INI 1"

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 July 2023 15:39 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/5 "2023-07-15T15:39:00Z")

</div>

See my prior msg since I updated it while you responded.

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [15 July 2023 15:50 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/6 "2023-07-15T15:50:05Z")

</div>

GREAT catch!  
I was expecting it to be a simple problem, but finding that .... phew  
THANKS!

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [15 July 2023 16:13 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/7 "2023-07-15T16:13:34Z")

</div>

Well, it is not quite solved yet.  
If the read file "test.txt" contains a blank line, the code gets swallowed.  
In the example here I have in the file after the "line 3" a blank line.  
In the output "Listing INI 2" nothing is shown, but "Listing INI 3" are line 3 and line 4 as one element of the object.

 ![flow_testfile_UI_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/754977a9722789e5fbe7abf55f37e1b800df10e8.png)  
Each line should be processed and also appear in the output as a separate line. Empty line is still debatable.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 July 2023 17:52 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/8 "2023-07-15T17:52:43Z")

</div>

Hmmm, it worked for me but that's probably because I put the data in an inject node. Try changing this line  
`m = m.replace("↵↵","")`  
to  
`m = m.replace("↵↵","\n")`

How is the file created in the first place?

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [15 July 2023 18:15 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/9 "2023-07-15T18:15:05Z")

</div>

For the moment ...  
The problem seems to be with empty line(s).  
If only one line a sort of replace could work, but had problem with multiple lines.  
Will come back with more details later ..

---

<div class="post-metadata">

**Author:** ![gNeandr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gneandr/32/73947_2.png) [@gNeandr](https://discourse.nodered.org/u/gNeandr)\
**Post date:** [17 July 2023 17:14 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/10 "2023-07-17T17:14:17Z")

</div>

After some testing it is clear that the discussed problem is not causally related to empty lines in the imported file.  
From what I can see, the problem is how `ng-repeat` deals with an array where elements are null. The '`null`' elements are caused by the `.split("\n")` of the imported file at the locations of the blank lines. `ng-repeat` simply aborts processing without a error message. At least I can't find any message in the logs.  
For my use case `ng-repeat` is probably not suitable. However the missing log is a bug ... for me!

Any further help / solution to process a file with "empty" lines as a complete array will be greatly appreciated.

---

<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:** [15 September 2023 17:15 UTC](https://discourse.nodered.org/t/show-a-simple-text-file-as-a-list-with-dashboard-template/79842/11 "2023-09-15T17:15:06Z")

</div>

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