How to write HTML code without repeating a Client.Println() each HTML line

Hello to everybody :slight_smile:

I'm using a Ethernet shield as web server.
Usually we need to write several times the client.println() before each HTML line.

Example:

...
client.println("<div style='width:240px; height:320px;'>"); 
client.println("<center><font color='blue'>ARDUINO</font color></center>");
client.println("
");
client.println("<table><tr>");
...

How can we group HTML code lines together, more or less like:

...
P = {
<div style='width:240px; height:320px;'>
<center><font color='blue'>ARDUINO</font color></center>


<table><tr>
}
...

Thanks to all ...

The backslash () character is your friend here:

client.println("<div style='width:240px; height:320px;'> \ 
<center><font color='blue'>ARDUINO</font color></center> \

 \
<table><tr>");

\ at the very end of a line is used to continue a line onto the next line. You can also add \n (and possibly \r) to add line feeds and carriage returns where you want them too.

Thanks,

is this method useful also to write javascript like this?

<html>
<head>
<script type="text/javascript">
function UPGRADE( )
{
    var tbl = document.getElementById("TBL");
    var rows = tbl.getElementsByTagName("tr");

    var cells = rows[0].getElementsByTagName("td");   
    cells[1].innerHTML = 20;

    var cells = rows[0].getElementsByTagName("td");
    cells[2].innerHTML = "IR DISABLED";

    var cells = rows[1].getElementsByTagName("td");   
    cells[1].innerHTML = "90%";

    var cells = rows[1].getElementsByTagName("td");
    cells[2].innerHTML = "TOO MUCH";

}
</script>
</head>


<body>
<table id="TBL" border="1" cellpadding="5">
<tr><td>Temperature</td><td>18</td><td>IR ACTIVE</td></tr>
<tr><td>Humidity (RH)</td><td>80%</td><td>Good</td></tr>
<tr><td>Light</td><td>900</td><td>OK</td></tr>
</table>
<input type="button" value="Upgrade" onclick="UPGRADE();"/>
</body>
</html>

Thelux
It should be.
I would use \n\ because some browsers don't like everything on one line.
Best regards
Jantje

Hi Jantie,

thanks for your suggestions...
but if I try this with javascript, it gives me an error

missing terminating " character.

:~

You will have to escape any quotes (") inside your string. You can do this with (again) a backslash:

char *test = "This is a \"test\" string";

hi Majenko,

yes, i did it:

client.println("<html> \
<head> \
<script type=\"text/javascript\"> \
...

and

client.println("<html> \
<head> \
<script type='text/javascript'> \
...
[code]

but same error, same line... [code]client.println("<html> \

[/code][/code]

Are you sure you have a \ at the very end of every line? It is quite common to get a space after a \ which causes problems. Make sure you go down each line and check for rogue spaces.

C allows strings to be broken as follows:

char text[] = "Twas brillig and the slithy toves"  /* all one string */
              "Did gyre and gimbal in the wabe"
              "All mimsy were the borogroves"
              "And the mome raths outgrabe";

But the maximum length may vary from compiler to compiler.

Yes Morris, I remember something like that.
It's close to what I saw few days ago somewhere in the net (unfortunately you see things when you don't need them :~ )

Maybe was it PROGMEM...? :frowning: