16

How do you write the following in the slim templating language?

<p>Join the <a href="">Google group</a> and let us know what you think, or what other features you’d like to see.</p>

I tried the following:

p
  ' Join the
  a href="" Google Group
  ' and let us know what you think, or what other features you’d like to see

But that doesn't work because the words 'Group' and 'and' do not have whitespace between them.

ylluminate
  • 12,102
  • 17
  • 78
  • 152
Erik
  • 4,268
  • 5
  • 33
  • 49

2 Answers2

24

Apparently you can add extra spaces after the quote:

p
  ' Join the
  a href="" Google Group
  '  and let us know what you think, or what other features you’d like to see
Erik
  • 4,268
  • 5
  • 33
  • 49
  • 1
    This is correct. The space after the quote becomes your left margin. You're free to add as many spaces as you like to the beginning of the line. – stonean Oct 06 '11 at 01:10
  • 12
    This syntax makes me want to vomit a little bit. – DickieBoy Mar 29 '16 at 13:46
  • Whoa, let's go with the other answer. – Andrew Koster Aug 23 '19 at 22:31
  • but this doesn't manage to get a space between "the" and "Google". I still can't figure this out. – Justin Bishop Dec 18 '21 at 05:33
  • To add leading/trailing spaces around the tag use the `<` and `>` characters after the `a`. See the [Slim Docs](https://rdoc.info/gems/slim/frames#trailing-and-leading-whitespace) for details. Also, for the vomiters, you can use `= link_to 'Google Group', '#'` instead of the anchor tag. It is a bit less nauseous. – Greg Tarsa May 11 '22 at 03:54
10

You can do

 p This is a paragraph with a link #{link_to 'embedded', 'http://google.com'}.

Rails tag helpers are just methods, so you can apply that logic to other methods inside views.

whatAboutJohn
  • 743
  • 1
  • 9
  • 16