Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

\n new line escape sequence in ERB

I'm not sure why "\n\n" is not adding two line breaks in my code below:

<%= (getparagraph(@geography, "geography")+"\n\n") if @geography != "Other" %> 

To clarify the method getparagraphs simply returns a paragraph of text. I'm trying to add two line breaks within the Ruby code without having to use <br/>

Any ideas? Everything I've read implies that it should work.

like image 307
Edward Castaño Avatar asked Jan 19 '23 07:01

Edward Castaño


2 Answers

Your helper has "paragraph" in its name so maybe you should wrap it in a paragraph and use CSS to add the appropriate spacing around the paragraph:

<% if @geography != "Other" %>
    <p>
      <%= getparagraph(@geography, "geography") %>
    </p>
<% end %>

You could always add a special class to the <p> if you need an extra spacing after this:

<% if @geography != "Other" %>
    <p class="geo-chunk">
      <%= getparagraph(@geography, "geography") %>
    </p>
<% end %>

and then in your CSS:

.geo-chunk {
    margin-bottom: 2em; /* Or whatever works */
}

And if this is to appear inside another <p> then you'd need to re-arrange the HTML a bit as you can't put a block element inside a <p>:

<div>
    <!-- The old <p> content ... -->
    <% if @geography != "Other" %>
        <div class="geo-chunk">
          <%= getparagraph(@geography, "geography") %>
        </div>
    <% end %>
</div>
like image 73
mu is too short Avatar answered Jan 24 '23 16:01

mu is too short


You're outputting HTML; whitespace is largely ignored upon rendering.

Use <br/> tags instead, and .html_safe.

like image 24
Dave Newton Avatar answered Jan 24 '23 16:01

Dave Newton