Skip to content

Horizontal Ruler Helper - Outlook compatible #716

Description

@Creativenauts

Created another useful helper that I'm sharing the community here. This is a nice way to add a horizontal ruler to your email template. Create file named "ruler.js" and place it in your helper folder.

Paste this code in the ruler.js file you created.

module.exports = function(options) {

	var color = options.hash.color;
	var spacing = options.hash.spacing;
	var height = options.hash.height;
	var width = options.hash.width;
	var widthType = '';
	var trimWidth = width.replace(/\D/g,'');
	var spacer = '';
	
	if (typeof color === 'undefined') color = '';
	if (typeof height === 'undefined') height = '';
	if (typeof width === 'undefined') width = '';

	if(width.match('%$')) {
		widthType = width = trimWidth+'%';
	} else if (width.match('px$')) {
		widthType = trimWidth+'px';
		width = trimWidth;
	} else {
		widthType = 'auto';
		width = trimWidth;
	}

	if (typeof spacing === 'undefined') {
		spacer = '';
	} else {
		spacer = '<tr height="'+spacing+'"><td height="'+spacing+'"></td></tr>';
	};

	var ruler = '<table align="center" border="0" cellpadding="0" cellspacing="0" width="'+width+'" height="'+height+'" style="width:'+widthType+' !important; height: '+height+'px !important;">\
		'+spacer+'\
		<tr height="'+height+'"><td bgcolor="'+color+'" align="center" valign="top" width="'+width+'" height="'+height+'" style="font-size: 0%; line-height:'+height+'px; mso-line-height-rule:exactly;">\
			<img src="https://spacergif.org/spacer.gif" width="'+width+'" height="'+height+'" />\
		</td></tr>\
		'+spacer+'\
	</table>';

	return ruler;
}

Then all you need to do is use this handlebar:

{{{ruler color="#009F8C" width="60" height="3" spacing="20"}}}

Spacing is above and below the ruler. You can leave it blank if you do not wish to have spacing before and after the ruler.

Here is an example of one of the templates I'm working on so you can see how it looks. Basically, it's the little rulers between the headline and sub headline text.

Hope you all enjoy and let me know if you have better solution as well because I really suck at javascript and coding in general :)

ruler
ruler-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions