Section

A section belongs to a theme and a category.

When an content editor adds a section within a page, Maglev creates an unique instance of the section based on its definition. This instance will store the content (text / image / links / ...etc) written by the content editor.

The section definition tells to the Editor UI how to build the content form.

When you genarate a new section through a Rails generator, you end up with the following folder structure.

Rails app root
└── app   
    ├── ...
    ├── controllers
    ├── ...
    └── theme 
        ├── sections
            ├── heroes
                └── heroe_01.yml
            └── cta
                └── cta_01.yml
        └── theme.yml
    └── views
        ├── ...
        └── theme
            ├── sections
                ├── heroes
                    └── heroe_01.html.erb
                └── cta
                    └── cta_01.html.erb
            └── layout.html.erb
        

The id of a section is the base name of their definition file name. Example: heroe_01 for heroe_01.yml.

Definition file

heroe_01.yml
name: "Heroe #1"
category: heroes
- label: "Title"
  id: title
  type: text
  default: My awesome title
- label: "Background image"
  id: background_image
  type: image_picker
  default: "/maglev-placeholder.png"

Template

Inside your section template file, you'll have access to a variable named maglev_section exposing the content written by the editors.

This variable owns a couple of attributes / methods.

The section must be wrapped by a single HTML node (DIV, SECTION, ...etc). This node will carry some important information about the section required by the UI editor. Those information are very important in order to refresh its content.

hero_01.html.erb
<%= maglev_section.wrapper_tag 
      class: 'py-8 px-4', 
      style: "background-image: maglev_section.settings.background-image" do 
%>
  <%= maglev_section.setting_tag :title, html_tag: 'h2', class: 'my-css-class' %>
<% end %>

You've got also the ability to not use our helpers and write plain HTML code instead. The example above can be also written like the following way:

heroe_01.html.erb
<div 
  class="py-8 px-4" 
  style="background-image: <%= section.settings.background-image %>"
  <%= section.dom_data %>
>
  <h2 <%= section.settings.title.dom_data %> class="my-css-class">
    <%= raw section.settings.title %>
  </h2>
</div>

Last updated