OUTRAGED PINK RACOON

Removing Extra Whitespace from Jekyll Templates

I noticed today in this very blog that I had an extra space between the comma and the tag names on my posts:

weird spacing on comma and tags

It got weirder still, because when I opened the inspect window I saw this extra whitespace in the html:

extra whitespace in html

Turns out, when you use the squiggle bracket to evaluate content (see below), it will render a new line even if it evaluates false.

example jekyll template

To fix this, we need to insert a ‘-‘ character beside the closing and opening brackets.

example jekyll template with - characters

This stops the rendering of the extra whitespace:

extra whitespace in html is gone

extra whitespace on comma and tags is gone