SLIM add space at start of multi line
Asked Answered
H

4

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
Hilmahilt answered 14/8, 2016 at 9:37 Comment(4)
You want to insert space before .mdl-cell div?Larger
no before the Create One here so that the text will be in 1 line "Don't have an account? Create one here"Hilmahilt
Can you put the required html, then I may give it a try?Larger
Try ' on new line between | Don't have an account? and = link_toSociability
H
20

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
Hilmahilt answered 15/8, 2016 at 9:11 Comment(4)
'Deeper'? This is like one of the first things you will see on Slim's Github readme :DSlyke
maybe it is now 3 years after the question was raisedHilmahilt
Sorry, I was probably in a snarky mood when I commented back in 2017 :/ Thanks for spreading the knowledge 👍Slyke
You can also do =< link_to .... < and/or > can be added to tags or = to add space before and/or after the content.Betimes
C
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
Cushman answered 14/8, 2016 at 11:34 Comment(4)
ended up adding span in front of the first line with >Hilmahilt
I fix my code now. But you have tried with this code?Cushman
this also worked seems we have 3 ways of solving the problem, none of which reduce the amount of codeHilmahilt
It seems so. I use this way because saw it in the slim doc rubydoc.info/gems/slim/…Cushman
G
3

You can use &nbsp; 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?&nbsp;
= link_to 'Create one here.', sign_up_path
Gynecium answered 14/8, 2016 at 9:41 Comment(6)
this is a bit messy, isnt their a more elegant way of achieving thisHilmahilt
You need |\&nbsp; instead of |&nbsp;Larger
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 codeHilmahilt
@ArupRakshit Why backslash is needed? I always use |&nbsp; You can attach &nbsp; at the end of text: "Don't have an account?&nbsp;". I looking for another solution when I started with Slim, but I found nothing.Lovelorn
after a few hours googling, another method i came across was span> Don't have an account? = link_to 'Create one here.', sign_up_pathHilmahilt
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.Soni
A
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?&nbsp;.

Aspia answered 15/8, 2016 at 13:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.