HTML-table as variable in HTML-mail?

Post Reply
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

HTML-table as variable in HTML-mail?

Post by magnussandstrom »

Hi!

I have a (variable) html table (as a html file) that I want to embed as a part of a html email in Switch. The email html has other Switch variables in it, but I can't figure out how to embed my table. Any suggestions?

ps. I also have the table as a CSV if that can be used some how.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTML-table as variable in HTML-mail?

Post by freddyp »

Put the HTML of the table in private data and place that variable in your HTML template.
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: HTML-table as variable in HTML-mail?

Post by magnussandstrom »

freddyp wrote: Tue Nov 29, 2022 9:11 am Put the HTML of the table in private data and place that variable in your HTML template.
Any suggestion how? The HTML-table is a file, not metadata.
User avatar
JimmyHartington
Advanced member
Posts: 282
Joined: Tue Mar 22, 2011 7:38 am

Re: HTML-table as variable in HTML-mail?

Post by JimmyHartington »

Could you read it in as Privatedata.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTML-table as variable in HTML-mail?

Post by freddyp »

I have not tested it, but I think the "Create file from template" app can insert a file into a file.
User avatar
JimmyHartington
Advanced member
Posts: 282
Joined: Tue Mar 22, 2011 7:38 am

Re: HTML-table as variable in HTML-mail?

Post by JimmyHartington »

I have this legacy script-code I have used earlier.

Code: Select all

/*
  This script reads the body of a file to private data.
*/

function jobArrived( s : Switch, job : Job )
{
	// Set some property stuff
	if(s.getPropertyValue('Debug') == 'Yes'){
		var debug = true;
	} else {
		var debug = false;
	}
	
		
	if(job.isFile())
	{
		// Make temp file
		var htmlData = File.read(job.getPath(), "UTF-8");

		
		// Set to PD
		job.setPrivateData("text", htmlData);

		
		// Debug
		s.log(1, 'TXT: ' + htmlData);
		
		// Send along
		job.sendToSingle(job.getPath());
		
	} else {
		// Not supporting folders
		if(debug) s.log(2, 'Input job was folder.');
	}
}
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: HTML-table as variable in HTML-mail?

Post by magnussandstrom »

Thanks Jimmy, but unfortunatly I do not have the scripting module.

What I need is to just copy the text from the html-file and insert as PrivateData, but maybe thats not possible without the scripting module?

Maybe someone can build the app: 'Text file 2 PrivateData'
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: HTML-table as variable in HTML-mail?

Post by Padawan »

Are you on windows or mac?
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: HTML-table as variable in HTML-mail?

Post by magnussandstrom »

Padawan wrote: Wed Nov 30, 2022 10:27 pm Are you on windows or mac?
Windows
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: HTML-table as variable in HTML-mail?

Post by Padawan »

You can use the "Run Command" App to achieve this. You can use either Cmd or PowerShell:

In Cmd using the type command:
Screenshot 2022-12-01 at 08.46.58.png
Screenshot 2022-12-01 at 08.46.58.png (46.56 KiB) Viewed 6151 times

In powershell using the Get-Content command:
Screenshot 2022-12-01 at 08.47.06.png
Screenshot 2022-12-01 at 08.47.06.png (46.55 KiB) Viewed 6151 times
The path to the text file can be set via variables of course. The content will be in the FileContent Private Data field.
User avatar
JimmyHartington
Advanced member
Posts: 282
Joined: Tue Mar 22, 2011 7:38 am

Re: HTML-table as variable in HTML-mail?

Post by JimmyHartington »

Padawan wrote: Thu Dec 01, 2022 8:49 am You can use the "Run Command" App to achieve this. You can use either Cmd or PowerShell:
This was a clever way to do it. :D
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: HTML-table as variable in HTML-mail?

Post by Padawan »

Thanks! The solution is not very elegant, but it works :)
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: HTML-table as variable in HTML-mail?

Post by magnussandstrom »

Padawan wrote: Thu Dec 01, 2022 8:49 am You can use the "Run Command" App to achieve this.
Thanks, it works great!

I ended up using Command Promt and command:

Code: Select all

type "%%InputFilePath%%"
Shawn_Anderson
Newbie
Posts: 8
Joined: Mon Apr 17, 2017 3:45 pm

Re: HTML-table as variable in HTML-mail?

Post by Shawn_Anderson »

Yeah the Run Command app is great for parsing text files into private data. I use these on the Mac in the zsh shell all the time

to read all the text

Code: Select all

cat %%InputFilePath%%
to read just the first line

Code: Select all

head -1 %%InputFilePath%%
to read everything after the first line

Code: Select all

tail -n +2 "%%InputFilePath%%"
to read lines that contain the string 'keyword'

Code: Select all

awk '/keyword/{print}' "%%InputFilePath%%"
Post Reply