Lorem Helper Paragraphs

Hi. I’m using the Lorem Ipsum Helper to generate paragraphs of text as follows:

<%= lorem.paragraphs 10 %>

This does generate 10 paragraphs of text, but there are no breaks between the paragraphs, so it looks like one large block of text when viewed in the browser. Is there a way to tell the helper to include paragraph tags on either side of each paragraph?

Thanks in advance :slight_smile:

1 Like

The lorem.paragraphs method separates paragraphs with newlines - it doesn’t create HTML paragraphs.

Try lorem.paragraphs(10).gsub(/(.+)$/, '<p>\1</p>').

That worked! Thank you very much :slight_smile:

I’ve got to learn me some RegEx skillz!

bhollis’s solution is elegant and succint, but here’s another solution you may like. It’s a bit more explicit (and, thus, verbose), and it gives you control over the number sentences in each paragraph.

<% 10.times do %>
  <p>
    <%= lorem.sentences 3 %>
  </p>
<% end %>

Turns out, there’s another Padrino helper (Middleman includes Padrino helpers) for this:

<%= simple_format lorem.paragraphs(3) %>

This will wrap each paragraph in a <p> tag. (In general, the helper does a bit more than that, such as turning single line breaks into <br> tags).

1 Like