Statamic killwhite

May 17, 2014 1 min read

My Statamic-generated page titles have been a mess because of extra whitespace and line breaks, which I eventually decided was unacceptable. I took inspiration from a Twig extension for killwhite, which removes excessive spaces and trims out tabs and returns.

So this...

<title>
	{{ if title != 'Home' AND title != '' }}{{ title }} | {{ endif }}
	{{ if taxonomy_name }}{{ taxonomy_name|title }} | {{ endif }}
	{{ if get:page }}Page {{ get:page }} | {{ endif }}
	{{ _site_name }}{{ if title == 'Home' }}: {{ _site_tagline }}{{ endif }}
</title>

...which might have generated...

<title>
	Some Post |     

	Working Concept
</title>

...just gets wrapped with a {{ killwhite }} tag...

<title>{{ killwhite }}
	{{ if title != 'Home' AND title != '' }}{{ title }} | {{ endif }}
	{{ if taxonomy_name }}{{ taxonomy_name|title }} | {{ endif }}
	{{ if get:page }}Page {{ get:page }} | {{ endif }}
	{{ _site_name }}{{ if title == 'Home' }}: {{ _site_tagline }}{{ endif }}
{{ /killwhite }}</title>

...and the result is beauty we can all appreciate:

<title>Some Post | Working Concept</title>
***
Matt Stein’s face

by Matt Stein

Full stack tinkerer, sporadic blogger and Craft CMS fan occasionally found on the devMode.fm podcast.

Tagged

Updated 6/17/19 at 1:37am