Whitespace in slim

The templating language slim is really, really great. It is so clean and beautiful compared to Rails’ default ERB.

But one gotcha was that if I had two span elements filled with text, and wanted some whitespace in between them, slim would delete all of the trailing whitespaces that I had typed in to the text in order to provide that separation.

I realized this is not actually a problem with slim – it was a problem with my approach.

The correct approach would be to use CSS to add margins to the spans so that there is blank space in between the text, rather than trying to hard-code that blank space into the strings themselves that I was displaying.

One Comment

  1. You can always add two spaces – unless your editor remove them on save.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s