Search code examples
ruby-on-railscomfortable-mexican-sofa

How to render nested child pages in Comfortable Mexican Sofa


So this is what I'm trying to accomplish, but I'm not sure where to start:

I have the following structure of pages: enter image description here

On the home page, I want to display each child to of Publications as a section. The two sections would be Alerts, and New Story of the Week. Then the latest published child of a section would render within that section. So on home page I would have the following sections and articles: Alerts -> Trouble in the East-1-20-2015 News Story of the Week -> Congress Ohverhauls Farm Bill

I've read the CMS wiki, but I don't know how to approach this. Do I use tags and collections?


Solution

  • You'll need to create a partial to get this working.

    Create one here /app/views/comfy/cms/content/_section_list.html.erb

    Then in the layout for the homepage add {{cms:partial:section_list}} to the html where you want the partial to be displayed.

    Then in _section_list.html.erb do something like:

    <% @cms_page.children.each do |section| %>
      <h1><%= section.blocks.where(identifier: 'header').first.content %></h1>
      <%= section.children.first.blocks.where(identifier: 'content').first.content %>
    <% end %>
    

    Note: be sure to get the block identifiers correct, I'm assuming you have a header and content in the snippet above.