Displaying line breaks with data from SQL

Hi,

I have an Input form, with a textarea field - data from it is stored directly in SQL.

What I’m trying to do, is display the text again with any line breaks that may have been input.

If I pit it back into a txtarea it is displayed with linebreaks - just to confirm that they are there.

New-UDInputField -Name 'desc' -Type 'textarea' -DefaultValue "$($ArgumentList.Description)"

But I want it displayed in a card or table.
I tried the code below, from another thread.

$Html = New-UDHtml "<div>$(($($ArgumentList.Description)).Replace('`n', '<br/>'))"

    New-UDCard -Title 'Description' -Content {
        $Html
    }

Any Pointers?

Hi @PorreKaj,
How does the HTML look of the card?

Can you paste the data into notepad++ and select “show all characters” to validate the `n is the actual linebreak being used.

I’m definitely not sure how to do that
The New-UDHtml outputs:
image

and the card shows:

I can test this more tomorrow, but when working with linebreaks in .txt files i just foreach loop it.
Test this:

$out = ""
foreach ( $line in $data) {
    $out = $out + $line + "<br>"
}

Also, remember to close your divs :slight_smile:

using that method i get

dfgdfg
dfgdfgd
fgdfgdf
gdfgdfg
dfgdfg

Copying the cell from SQL into notepad++ gives:

image

Hi @PorreKaj
give this a go:

$out = $out -replace "`n","" -replace "`r","<br>"

I added it to when the data is stored

-SqlParameters @{ 

   Created = Get-Date
   PartnerID = [int]$PartnerID
   Title = "$TitleTXT"
   Description = $DescriptionTXT -replace "`n","" -replace "`r","<br>"
   TimeEstimate = $null
  Requester = "$User"
  } | Out-Null

But that only removed anything in between the lines :smiley:
dfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfgdfg

same result in the console - thats great - its a bit easier to play with.

I run this

PS C:\Users\reh\Documents\GitHub\ITDashboard\Beta.IT> $test = "ert
>> ert
>> Ert
>> Ert"
PS C:\Users\reh\Documents\GitHub\ITDashboard\Beta.IT> $test | clip    

And copy it into NP++ to confirm the line breaks are the same:

image

then run your code

PS C:\Users\reh\Documents\GitHub\ITDashboard\Beta.IT> $test -replace “n","" -replace "r”,“

ertertErtErt

And here it also just removes the spaces, so it must be:

$test -replace “`n”,“

and there we go:
ert<br>ert<br>Ert<br>Ert

Now its just the matter og getting it to display.

Edit:

Finally

$preHTML = $($($ArgumentList.Description) -replace "`n","<br>")

New-UDCard -Title 'Description' -Content {

New-UDHtml -Markup "<div>$preHTML</div>"

       }
1 Like

Awesome!
Good job :slight_smile: