Setting

A section or block definition comes with a list of settings. Those settings will be used by the editor UI to render the proper content form of a section (or block).

For instance, if your section includes 2 settings, let's say a title (text) and a background image (image), then the editor UI will generate for this section a form with 2 input elements: a text input for the input and an image picker to select the background image.

Default definition setting attributes

Available types and their options

text

Display a text input, simple or a rich text editor depending on the setting options.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Title"
  id: title
  type: text
  # html: true
  # line_break: true
  # nb_rows: 5

Usage in the HTML/ERB template:

app/views/theme/sections/sample.html.erb
<%= maglev_block.setting_tag :title, html_tag: :h2 %>

image

Display an image picker to let the content editor choose or upload any image.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Screenshot"
  id: screenshot
  type: image
  default: "/samples/images/default.svg"

Usage in the HTML/ERB template:

app/views/theme/sections/sample.html.erb
<%= maglev_section.setting_tag :screenshot, class: 'my-css-class' %>

List of properties:

<p><img src="<%= maglev_section.settings.screenshot.url %>" alt="<%= maglev_section.settings.screenshot.alt_text %>" /></p>

Display a link picker. The content editor will have the choice between a link to an external URL, a page or an email address.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Call to action"
  id: cta_link
  type: link
  with_text: true
  default: "/"

Usage in the HTML/ERB template:

app/views/theme/sections/sample.html.erb
<%= maglev_section.setting_tag :cta_link %>

List of properties:

collection_item

This setting type allows content editors to select an instance of any ActiveRecord class of the main Ruby on Rails application. For instance, in your e-commerce site, if your section is named featured_product_01, chances are big that you will need a collection_item setting type to let your editors pick the product of their choice among the products table.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Product"
  id: collection_item
  type: collection_item
  collection_id: products

Usage in the HTML/ERB template:

app/views/theme/sections/sample.html.erb
<%= maglev_section.setting_tag :product, class: 'featured-product' do |product| %>
  <h2><%= product.name %></h2>
  <p><%= number_to_currency product.price %></p>
<% end %>

If the content editor hasn't chosen an item or if the item doesn't exist anymore, the setting tag won't rendered.

List of properties:

color

Display a color picker. The content editor will have to choose between a selection of color presets defined by the developer.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Background color"
  id: background_color
  type: color
  presets: ["#F87171", "#FBBF24", "#34D399"]
  default: "#F87171"

Usage in the HTML/ERB template:

app/views/theme/sections/sample.html.erb
<div class="banner" style="background-color: <%= section.settings.background_color %>">
  <h2>Hello world</h2>
</div>

List of properties:

checkbox

Display a toggle input.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Display warning message ?"
    id: cta_link
    type: checkbox
    default: false

Usage in the HTML/ERB template:

app/views/theme/sections/sample.html.erb
<% if section.settings.display_warning_message %>
  <div>My warning message</div>
<% end %>

List of properties:

icon

Display a popup to select an icon among a set of icons. Follow the instructions here to set up the icon library.

Definition:

app/theme/sections/sample.yml
settings:
- label: "Icon"
    id: cta_icon
    type: icon
    default: 'fa fa-github'

Usage in the HTML/ERB template:

<div>
  <%= maglev_section.setting_tag :icon, html_tag: 'i' %>
</div>

Last updated