CasparCG client HTML template

Hi everyone,

we have been using casparCG server with casaprCG client the last 8 years. Our templates for graphics are flash templates.
Using casparCG client, we set a key (f0) and a text that goes in the value field. We can write a text with one, two or more lines using the enter key (for new paragraph). Everything is fine with flash templates.
This year we decided to move on and change all out flash template graphics to HTML.
Using again the casparCG client for passing text as a value, we found that we cannot send text with a new paragraph (enter key). With one line text, everything runs smoothly. If there is an enter in the text, the text does not update.
The graphic is designed using HYPE (javasript code has all the functions for communication with casaprCG).
With little knowledge of coding that I have, I can see that pressing enter key in the text, CasparCG client does not use “\n”. It simply changes a line. If I send a custom command with “\n” everything can work correct.
The idea is to write simple text in the casaprCG client without any special characters, just like we did with the flash templates.
CasparCG server 2.3.3
CasparCg client 2.2

thank you

Would it be possible to add code to replace the <CR><LF> sequence that the client sends with a \n in the templates JavaScript code?

Yes.

 if (field !== undefined && value !== undefined) {
      // Replace <CR><LF> with \n for multiline text
      value = value.replace(/<CR><LF>/g, "\n"); // Replace <CR><LF> with \n
      data[field] = value;
}

If I write in casparCG client a text like: “First line of text CR LF (with the brackets correctly) Second line of text” the code runs ok and the result is fine. However, if I just press the Enter key for a new line of text, it does not work. Cheking the console of casparcg server, I see that it sends this:

[2023-07-18 14:36:38.336] [info]    Received message from 127.0.0.1: CG 1-20 ADD 1 "HTML TEMPLATE SKYPE/HTML TEMPLATE SKYPE" 1 "<templateData><componentData id=\"f0\"><data id=\"text\" value=\"First line of text
[2023-07-18 14:36:38.336] [info]    Second line of text\"/></componentData></templateData>"\r\n

sorry but the CR and LF are not displayed in the forum. they are correctly placed in the code of JS too,

I use html template with javascript code and I send data in json format from the standard client.

If I try to put new line in the field it does fire an error when parsing data and \n doesn’t have any result other than display it as a text.

The way that I found is to put <br> (line break element) to make a new line.
But if you are sending data in xml format that could not work either.

They are, if you format all code and log blocks with that code formator. The button is labled </>. I did that for you for now, but I did that already too many times in this forum…

You need to do that in the code of the template, it seems that Caspar can cope with variable contents that contain a <CR><LF> sequence.

of course you can do that in code, but I sent it as value in the official client “first_name<br>last_name” and in the “div” element of the template appears in two lines.

this works only in “json” format, in xml the <> mess up and I don’t know how and if you can escape it

(I’m referring to the “Send as JSON” option in the Client, to clear any doubt)

I see your point, but @thraki mentioned, that he wants to “just type” and not think about special formatting in the client while typing, So he will have no other chance as to try to do the trick in the templates code.

ok, I read a bit better the second message

by the way, I tried to see what does arrive in the template if you send the “return” key in the text
just by console.log(data), without any manipulation
if json = Uncaught SyntaxError: Invalid or unexpected token
so doesn’t seem to be a possible way

if xml seems to passthrough as console log message is splitter in two
but I’m not very familiar to figure out how to parse correctly the xml input data and see if the “return” could be catch and handle properly