Skip to content

Fragment ​

Reusable chunks of content — a footer text, a hero tagline, a contact blurb — editable from the admin and usable anywhere in your views. Fragments are grouped by namespace and identified by key.

Columns ​

ColumnTypeNotes
keystringunique within its namespace
namespacestringgrouping (e.g. footer, home)
titlejsonbtranslated label
contentjsonbProseMirror document
positionintegerordering within the namespace

Behavior ​

  • Includes Contentable, Translatable (title, content), Keyable and strip_attributes
  • acts_as_list scope: [:namespace] with an ordered scope
  • to_s returns "namespace.key"

Usage ​

ruby
fragment = Fragment.find_by(namespace: "footer", key: "tagline")
fragment.formatted_content # => safe HTML

Pages can also be composed from fragments via the Fragmentable concern and the page_fragments configuration matrix.

Released under the MIT License.