Creating a Custom Print Template in HTML/CSS/Javascript

I’m looking to add custom functionality to my website. My site runs in the Hugo static site generator. I would ask the question on the community forms of Hugo, but this is more of a HTML/CSS/Javascript thing. With Hugo its very easy to author content pages with markdown. Hugo translates my content authored in markdown into HTML/CSS. This makes it very easy to write content and publish it on my website. In addition I create newsletters for my customers every so often and have been doing this all in HTML outside of Hugo because I want email them to my customers and its easier to do this way. But as a write more and more newsletters the html markup is getting in the way and I want to embed my html/css code into a hugo tempate so I can create news letters using the markup engine. But this presents a problem with generating the newsletter content for emails because the HTML and CSS code needs to be different from my website.

I would like to have a specific style for the email version of these newsletters. I was thinking about using a Javascript button on each news letter that when pressed would show a new window with the content, using differnt html/css styles, that makes the page email friendly as described here that I could just copy and paste into an email. I was wondering if anyone has any experience with this and could get me started in the right direction. Im pretty good with HTML/CSS, but I don’t really know JS that much.

Is this topic relevant to these forms? Any suggestions?

I’ve never worked with Hugo, but I’ll take a shot at this one :slight_smile:

What you could do is, setup a CSS script that styles you email as you like, and when you press the button that you described, it adds the CSS script to the page.
You would need a button on screen

You would need a JS script with some code that is run when the button is clicked.
You need to add all the code below to the JS script, and add the JS script to the head of your html file.
You also need jQuery.
Well, I’ve written the below using the jQuery library.
You can find plain old JS equivalents of all of the below:

// will call the loader() function once the page has finished loading

// loader function
// runs once page has loaded
// adds click event to the button with id btnClickMe
function loader()

// is called when the button is clicked
// this function will add the css script to the html page
// make sure the href is correct
function catchClick()
var head = document.getElementsByTagName(‘head’)[0];
var link = document.createElement(‘link’); = cssId;
link.rel = ‘stylesheet’;
link.type = ‘text/css’;
link.href = ‘/link/to/you/stylesheet.css’; = ‘all’;

I haven’t tested this out, but it should be on the right track.

I hope this helps.

Thank you. Hugo has HTML templates that I can use to generate content from markdown files so I can easily implement this. Thank you for the information I will test it out in the coming weeks and see how it works.