---
url: /reference/models/fragment.md
---
# 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](/reference/concerns/contentable), [Translatable](/reference/concerns/translatable) (`title`, `content`), [Keyable](/reference/concerns/keyable) and `strip_attributes`
* `acts_as_list scope: [:namespace]` with an `ordered` scope
* 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_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](/reference/concerns/fragmentable) concern and the `page_fragments` configuration matrix.
