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
| Column | Type | Notes |
|---|---|---|
key | string | unique within its namespace |
namespace | string | grouping (e.g. footer, home) |
title | jsonb | translated label |
content | jsonb | ProseMirror document |
position | integer | ordering within the namespace |
Behavior
- Includes Contentable, Translatable (
title,content), Keyable andstrip_attributes acts_as_list scope: [:namespace]with anorderedscope- A
search(query)scope, case-insensitive, matching the key (namespace.key), the title or the text of the content in the current locale. The admin's fragments index searches with it. to_sreturns"namespace.key"
Usage
ruby
fragment = Fragment.find_by(namespace: "footer", key: "tagline")
fragment.formatted_content # => safe HTMLPages can also be composed from fragments via the Fragmentable concern and the page_fragments configuration matrix.