Building a view

‹ Back

Meta tags

Make sure your view has all the necessary meta tags defined at the top of your page.

A typical show view would have a title, short description and potentially a share image:

<%
  content_for :title, resource.title
  content_for :og_description, resource.short_description
  content_for :meta_image, resource.image.thumb("1200x630#").url
%>

An index or hard-coded view would typically have more hard-coded values.

Note: Title and description here will be overridden by the Koi SEO tab if that is implemented for this particular resource or collection.


Layout

As you may have read in the page layouts section, you can also define content for a sidebar yield to make the page render in a two column layout:

<%
  content_for :title, resource.title
  content_for :og_description, resource.short_description
  content_for :meta_image, resource.image.thumb("1200x630#").url
%>

<% content_for :sidebar do %>
  My sidebar
<% end %>

My content

Sensible view logic

Some things to keep in mind when developing your views:

  • If you have a consistent sidebar across multiple templates, consider moving it in to a partial.
  • When there are no items in a listing, make sure you aren't rendering an empty page.
<%
  content_for :title, "Latest news"
  content_for :og_description, "Find out what's happening in and around your personal space."
  content_for :meta_image, asset_path("banners/news.jpg")
%>

<%= render "news_items/sidebar" %>

<% if collection.present? %>
  <p>No news is good news!</p>
<% else %>
  <div class="news">
    <% collection.each do |news_item| %>
      <div class="news--item">
        <%= news_item.title %>
      </div>
    <% end %>
  </div>
<% end %>

<% content_for :below_layout do %>
  <div class="news--footer">
    Subscribe for updates
  </div>
<% end %>