Can you put newlines in content of text objects in UDElements?

Trying to have a UDElement show text data in a few rows, attempted to do this but it’s all one one line. I’ve also tried using -join with newline characters with no luck.

 $Response_data = "There were $hits hits from $total different assessors. `r`n The initial scan of this file was on $scandate"
 Set-UDElement -id "OTX_hash_response" -Content {$Response_Data}

Any thoughts would be appreciated!

I too am wondering this. Nothing I have tried has succeeded. Even splitting the string on [Environment]::newLine doesn’t work.

Hi @mgeorgebrown89,

Either do a New-UDParagraph for each of your elements, or play around with the HTML " < br > " (without spaces)
Uncertain if new-udlelement strips the html code, if so you can use new-udhtml :slight_smile:

1 Like


I also came across this need in my project and helped myself with New-UDHtml
Here is one code snipped for a pure text and one for a code text (used for JSON text).

$Message = "first line`r`nsecond line"
$Message = $Message -replace '\r\n', '<br />' -replace '\n', '<br />' -replace '\r', '<br />'
New-UDHtml -Markup "<p>$Message</p>"

$Json = [PSCustomObject]@{
    Timestamp = (Get-Date).ToString()
    Value = 2
    ID = (New-Guid).Guid
$JsonMessage = ConvertTo-Json $Json
New-UDHtml -Markup "<pre><code><font size=`"2`">$JsonMessage</font></code></pre>"