HTML code on multiple lines

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Rick0825
Junior Coder
Posts: 26
Joined: Sun Mar 05, 2023 5:30 pm

HTML code on multiple lines

Post by Rick0825 » Sat Jul 06, 2024 4:52 pm

I have an email that im trying to add HTML code to the body of the email. It works great when all the code is on the same line but..... Its WAY to much on 1 line. I used word wrap but its still to messy. Does it have something to do with creating the body in a variable? Is there any other way?

Code: Select all

Let>SMTP_HTMLBODY=1
Let>body=<html>
<head>
<style>
table {
  font-family: Arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}
tr:nth-child(even) {
  background-color: #f2f2f2;
}
</style>
</head>
<body>
<h2 style="font-size: 18px;">Alarms</h2>
<table>
  <tr>
    <th>Alarm</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>Alarm 1</td>
    <td>Active</td>
  </tr>
  <tr>
    <td>Alarm 2</td>
    <td>Inactive</td>
  </tr>
</table>
</body>
</html>

User avatar
Grovkillen
Automation Wizard
Posts: 1048
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: HTML code on multiple lines

Post by Grovkillen » Sat Jul 06, 2024 6:38 pm

Use Labeltovar
Let>ME=%Script%

Running: 15.0.24
version history

Rick0825
Junior Coder
Posts: 26
Joined: Sun Mar 05, 2023 5:30 pm

Re: HTML code on multiple lines

Post by Rick0825 » Sat Jul 06, 2024 6:53 pm

I found a solution but have no idea how or why it works, but maybe it can help others.

Code: Select all

Let>SMTP_HTMLBODY=1
LabelToVar>MyLabel,body
IncludeFromVar>body

/*
MyLabel:
<html>
<head>
<style>
table {
  font-family: Arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}
tr:nth-child(even) {
  background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
  <tr>
    <th>Alarm</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>Alarm 1</td>
    <td>Active</td>
  </tr>
  <tr>
    <td>Alarm 2</td>
    <td>Inactive</td>
  </tr>
</table>
</body>
</html>
*/


Rick0825
Junior Coder
Posts: 26
Joined: Sun Mar 05, 2023 5:30 pm

Re: HTML code on multiple lines

Post by Rick0825 » Sat Jul 06, 2024 6:56 pm

Thank you Grovkillen. I did not see your reply until after my post but im glad I was on the right track.

Rick0825
Junior Coder
Posts: 26
Joined: Sun Mar 05, 2023 5:30 pm

Re: HTML code on multiple lines

Post by Rick0825 » Sun Jul 07, 2024 1:28 am

Another question then. What if I wanted to change the text to a variable inside the HTML table as shown here.

Code: Select all

<body>
<table>
  <tr>
    <th>%Alarm%</th>
    <th>%Status%</th>
  </tr>
  <tr>
    <td>%Alarm 1%</td>
    <td>%Active%</td>
  </tr>
  <tr>
    <td>%Alarm 2%</td>
    <td>%Inactive%</td>
  </tr>
</table>
</body>
I created the variables using GetClipBoard but they display in an email as %Alarm% inside the table. I also tried '%Alarm%'. They do however display correctly when using MessageModal.

User avatar
Grovkillen
Automation Wizard
Posts: 1048
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: HTML code on multiple lines

Post by Grovkillen » Sun Jul 07, 2024 8:38 am

LabelToVar>LabelName,VariableName[,WantLineBreaks,IgnoreVariables,EndToken

https://www.mjtnet.com/manuals/b/v15/in ... ntext=3980
Let>ME=%Script%

Running: 15.0.24
version history

Rick0825
Junior Coder
Posts: 26
Joined: Sun Mar 05, 2023 5:30 pm

Re: HTML code on multiple lines

Post by Rick0825 » Sun Jul 07, 2024 4:19 pm

Thanks, but im not sure this was helpful?
LabelToVar>LabelName,VariableName[,WantLineBreaks,IgnoreVariables,EndToken
https://www.mjtnet.com/manuals/b/v15/in ... ntext=3980
The line breaks & ignore variables default to 0 if that's what you were trying to point out?

There were 2 issues with my code.
1. The assigned variables must be above the LabelToVar> command.
2. MS does not like the % sign. In my HTML code I had "width: 100%" that I had to change to "width: 600".

Im sure these are rookie mistakes but that's why I continue to post in the beginner forum. So much to learn. :D

User avatar
Grovkillen
Automation Wizard
Posts: 1048
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: HTML code on multiple lines

Post by Grovkillen » Sun Jul 07, 2024 6:57 pm

1.
Yes the command needs to be above the label.

2.
Let>PERCENT=%

Code: Select all

width:100%PERCENT%
Let>ME=%Script%

Running: 15.0.24
version history

Rick0825
Junior Coder
Posts: 26
Joined: Sun Mar 05, 2023 5:30 pm

Re: HTML code on multiple lines

Post by Rick0825 » Mon Jul 08, 2024 12:36 am

#2 = Very clever. Thank you!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts