Creating a Sales Page: The Layout

This is a premium course, which you can purchase below.

Buy Now

In my explorations, I found that using Repeaters for each section of my page was the most flexible option, though, yes, probably not what was intended.


When you work with a Repeater, you have to loop over its elements:

<% current\_page.content(:problem).each do |p| %>
<h2<%=p.content(:title)%></ph2
<p><%=p.content(:summary)%></p>
<% end %>

You can also wrap this with an if statement if you're not sure whether a bit of content is present:

<% if(current\_page.content(:problem).present? %>
...
<% end %>

I find that working with partials is much easier, because you can plug them in where you need them. They can work like components in a Vue or React app as well.
For instance, my "hero" partial doesn't need to access the current_page stuff, you can pass the page to it, like this:

<%= render "hero", locals: {page: current\_page.content(:problem).first } %>

A bit verbose, but it does separate the hero from the implementation details.