7

I am trying to add a space to the start of my slim template where I have had to break the text due to a link, I cant for the life of me work this one out

.mdl-cell.mdl-cell--4-col-phone.mdl-cell--8-col-tablet.mdl-cell--12-col-desktop
  | Don't have an account?
  = link_to 'Create one here.', sign_up_path
Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
Boss Nass
  • 3,384
  • 9
  • 48
  • 90

4 Answers4

19

found after some deeper research that the slim way is to use > so the new code is, which forced whitespace at the end of the first line

span> Don't have an account? 
= link_to 'Create one here.', sign_up_path
Boss Nass
  • 3,384
  • 9
  • 48
  • 90
13

with a simple quote ' the slim add a space

.mdl-cell.mdl-cell--4-col-phone.mdl-cell--8-col-tablet.mdl-cell--12-col-desktop
  | Don't have an account?
  '
  = link_to 'Create one here.', sign_up_path
Breno Perucchi
  • 873
  • 7
  • 16
3

You can use   to add space between html elements:

.mdl-cell.mdl-cell--4-col-phone.mdl-cell--8-col-tablet.mdl-cell--12-col-desktop
| Don't have an account? 
= link_to 'Create one here.', sign_up_path
Michał Zalewski
  • 3,123
  • 2
  • 24
  • 37
  • 1
    this is a bit messy, isnt their a more elegant way of achieving this – Boss Nass Aug 14 '16 at 09:46
  • You need `|\ ` instead of `| ` – Arup Rakshit Aug 14 '16 at 09:58
  • this just seems so messy, and i thought the purpose of slim was to reduce the number of lines of code. this now makes this file more lines than haml for the same code – Boss Nass Aug 14 '16 at 10:10
  • 1
    @ArupRakshit Why backslash is needed? I always use |  You can attach   at the end of text: "Don't have an account? ". I looking for another solution when I started with Slim, but I found nothing. – Michał Zalewski Aug 14 '16 at 12:21
  • after a few hours googling, another method i came across was `span> Don't have an account? = link_to 'Create one here.', sign_up_path` – Boss Nass Aug 14 '16 at 12:44
  • I have had the same problems. I am glad this question was asked. I crigne everytime I have to deal with spaces in slim. Apparently there is a git issue thread on this, they keep adding this space fix. – Abhishek Dujari Aug 15 '16 at 14:42
1

If you have a space after | Don't have an account?, it will be honored. Perhaps your text editor is set to remove all trailing whitespace.

If that's the case, then the cleanest approach is to simply use | Don't have an account? .

jeffdill2
  • 3,968
  • 2
  • 30
  • 47