Cummings.P
Cummings.P

Reputation: 53

How to break a line much like <br /> or \n in embedded ruby within a Haml file?

I am having trouble breaking a line in embedded ruby within a Haml file. I have the following code:

= "#{event.setup_time} Minute Setup" unless event.setup_time == nil
= "#{event.teardown_time} Minute Teardown" unless event.teardown_time == nil

But it is printing it all in one string. Any suggestions? Cheers ~

Upvotes: 0

Views: 508

Answers (2)

Michael Gaskill
Michael Gaskill

Reputation: 8042

You can do this:

= "#{event.setup_time} Minute Setup" unless event.setup_time == nil
%br
= "#{event.teardown_time} Minute Teardown" unless event.teardown_time == nil

This will insert a <br> element between the two strings.

You can also do this:

%p
  = "#{event.setup_time} Minute Setup" unless event.setup_time == nil
%p
  = "#{event.teardown_time} Minute Teardown" unless event.teardown_time == nil

This will place the two strings within different <p> elements.

Upvotes: 0

Raffael
Raffael

Reputation: 2669

You can use a <br /> HTML tag like so:

= "#{event.setup_time} Minute Setup"       if event.setup_time.present?
%br/
= "#{event.teardown_time} Minute Teardown" if event.teardown_time.present?

If you want to avoid the <br /> if unnecessary, this might be your solution instead:

- if event.setup_time.present?
  = "#{event.setup_time} Minute Setup"       
  %br/
- if event.teardown_time.present?
  = "#{event.teardown_time} Minute Teardown" 

Upvotes: 1

Related Questions