# Content

Source: https://developers.swell.is/frontend-api/content

**Swell.js:**

Retrieve pages, blog posts, and records from your store's own content models to display in a storefront. With the Frontend API you can query content records, but not create or edit them.

Both methods take a content type as their first argument, which is the collection name of the content model — for example `pages`, `blogs`, or `blog-categories` — along with any custom content models defined in your store.

### List content

Returns a list of content records of the given type, with offset pagination using `limit` and `page` (the default limit is 15). The query object is passed through to the API, so `where`, `expand`, and `search` are also supported. The response is an object containing `count`, `page`, `limit`, and `results`.

**List content**

**swell.js**

```javascript
await swell.content.list('pages', {
  limit: 25,
  page: 1
})
```

### Get a content record

Returns a single content record by slug or ID. An optional third argument accepts the same query parameters as `list`. Which fields come back depends on the content model. Records include `id` and `date_created`, and page and blog models typically include `title`, `slug`, `content`, `published`, and `meta_description`. Some content models also return a `sections` array, where each section has an `id` and a `type` along with whatever additional fields that section type defines. Field names are snake_case by default; if you initialize the client with `useCamelCase: true`, they are returned as camelCase instead.

**Get a content record**

**swell.js** `By slug`

```javascript
await swell.content.get('pages', 'about-us')
```

**swell.js** `By ID`

```javascript
await swell.content.get('pages', '5c15505200c7d14d851e510g')
```

**swell.js** `Example result`

```json
{
  "id": "5c15505200c7d14d851e510g",
  "title": "About us",
  "slug": "about-us",
  "published": true,
  "content": "<p>We opened our first shop in 2013.</p>",
  "meta_description": "Learn how we got started.",
  "date_created": "2024-05-14T18:22:11.000Z"
}
```

> **Note:** Content requests are not cached between calls. Every call to `swell.content.get()` sends a request to the API, so cache the result in your storefront if you need to avoid repeat requests for the same record.

### Content preview

Every `swell.content.get()` request sends a `$preview` query parameter, set to the `previewContent` option passed to `swell.init()`, which defaults to `false`. Because the option is applied before the query argument, you can pass `$preview` in the query to override it for a single request. `swell.content.list()` does not send this parameter.

**Content preview**

**swell.js**

```javascript
// Send $preview=true on every content.get() request
swell.init('<store-id>', '<public_key>', {
  previewContent: true
})

// Or override it for a single request
await swell.content.get('pages', 'about-us', { $preview: true })
```
