> For the complete documentation index, see [llms.txt](https://api-docs.devhub.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api-docs.devhub.com/content-resources/pages.md).

# Pages

## Pages

The Pages resource is how individual pages are added to a [Site](/core-resources/sites.md) (or Site template)

## Page model

### Page object

A page contains the following fields

| Name               | Type              | Description                                                                                                                                                                                           |
| ------------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `site_id`          | `integer`         | **required**                                                                                                                                                                                          |
| `name`             | `string`          | **required** Name of the page. Used in navigation menus and breadcrumbs                                                                                                                               |
|                    |                   |                                                                                                                                                                                                       |
| **Optional**       |                   |                                                                                                                                                                                                       |
| `column_widths`    | `list` of `lists` | Percentage widths of the rows and columns within the Page. Examples: Single column page `[[100]]` *(default)*, Two columns within one row `[[50, 50]]`, Multiple rows and columns `[[100], [50, 50]]` |
| `modules`          | `list`            | List of Page Module/Component objects to publish to the Page with positional details including `row`, `column`, and `order`                                                                           |
| `path`             | `string`          | Specific path within the Site where you want to publish the page (i.e. `/contact-us/`)                                                                                                                |
| `title`            | `string`          | HTML `<title>` tag for the Page. Defaults to the `name` parameter if not provided                                                                                                                     |
| `clone_id`         | `integer`         | Page ID of a page you want to duplicate/clone. More info under the Clone/Duplicate example                                                                                                            |
| `custom_fields`    | `array`           | Structured custom field values                                                                                                                                                                        |
| `custom_page_type` | `string`          | For pages of `type` of `template_page` this is the template name reference (i.e. `service_template`                                                                                                   |
| `id`               | `integer`         | Unique id of the page                                                                                                                                                                                 |
| `active`           | `boolean`         | Is the page published. For production environments `active=true` is needed for the page to render, otherwise it will 404                                                                              |
| `type`             | `string`          | Type of the page. Available types are `default` (default), `template_page`. When using `template_page`, you must also pass `custom_page_type`                                                         |
| `locations`        | `list`            | Assignment/tagging of Location object IDs                                                                                                                                                             |
| `meta_description` | `string`          | Meta description value for the page                                                                                                                                                                   |
| `meta_keywords`    | `string`          | Meta keywords for the page                                                                                                                                                                            |
| `noindex`          | `boolean`         | Should a noindex attribute be added to the page                                                                                                                                                       |
| `canonical`        | `string`          | Override the self-referencing canonical tag by supplying a full URL to the new canonical                                                                                                              |

### Custom fields

Each page that is built on the platform can be assigned `custom_fields` values that can then be used throughout HTML templates.

This field can contain a structured JSON object with support for nested values.

```
"custom_fields": {
  "headline_one": "Example headline one",
  "headline_two": "Example headline two",
  "bullet_points": [
    "Bullet point one",
    "Bullet point two"
  ]
}
```

From this example, the value can be used in templates via template variable (`{{ page.custom_fields.headline_one }}`)

Publishing `custom_fields` to support the Dashboard editing experiences need to follow the associated template fields, field slugs and serialization formats. For more information on how you would serialize/form the data within `custom_fields`, see [Custom fields](/advanced/custom-fields.md)

## List pages

List all pages within a Site

```
GET /api/v2/pages/?site_id=12345
```

### Parameters

| Name      | Type     | Description                                                 |
| --------- | -------- | ----------------------------------------------------------- |
| `site_id` | `string` | **required** ID of the `Site` you want to get the pages for |

### Response

```
{
  "meta": {
    "limit": 20,
    "next": "/api/v2/pages/?limit=20&offset=20",
    "offset": 0,
    "previous": null,
    "total_count": 5
  },
  "objects": [
    {
      "active": true,
      "id": 22225773,
      "name": "Home",
      "nofollow": false,
      "path": "/",
      "resource_uri": "/api/v2/pages/22225773/",
      "site_id": 12345,
      "type": "default"
    },
    {
      "active": true,
      "id": 22225774,
      "name": "Contact Us",
      "nofollow": false,
      "path": "/contact-us/",
      "resource_uri": "/api/v2/pages/22225774/",
      "site_id": 12345,
      "type": "default"
    },
    ...
  ]
}
```

## Get a single page

Fetch the Page detail using the `Page.id`

```
GET /api/v2/pages/:id/
```

### Response

```
{
  "site_id": "12345",
  "path": "/",
  "title": "Site Home Page",
  "name": "Home",
  ...
}
```

## Create a page

```
POST /api/v2/pages/
```

#### Required fields <a href="#required-fields" id="required-fields"></a>

* `site_id`
* `path`
* `name`

#### Example

```
{
  "name": "Our Services",
  "path": "/our-services/",
  "site_id": 12345
}
```

### Response

A status code of `201 created` is returned on a successful creation and contains the created page object as JSON. See the [Get a single page](/content-resources/pages.md#get-a-single-page) section for an example Page object.

### Cloning/duplicating a page

We have a `clone_id` parameter that can be used to easily duplicate/clone an entire page, including all of its modules and content.

This allows for a simple payload without the need to provide all the modules and page fields from the original.

**Example:**

```
{
  "clone_id": 512345,
  "site_id": 12345,
  "name": "Duplicated page name"
}
```

## Update a page

```
PUT /api/v2/pages/:id/
```

You can `PUT` a partial or full object to the detail endpoint to update/change values on the Page object. If using a partial object, you must insure that the primary page `id` is part of the payload.

***

## Templated pages

Specific guide on how to publish and manage templated pages&#x20;

What you will need to publish a templated page

* `site_id` - The Site ID where the page will be published
  * Typically you have one Site ID for the Corporate/Primary Site, and individual Site IDs for each Local site
* `custom_page_type` - Template name reference associated with the Page template you are publishing (i.e. `service_template)`
* List of the fields (slugs and field types) associated with the template. See below

All content within templated pages is managed within `custom_fields`

> Publishing `custom_fields` to support the Dashboard editing experiences need to follow the associated fields for the page template and their field types. For more information on how you would serialize/form the data within `custom_fields`, see [Custom fields](/advanced/custom-fields.md)

Example of publishing a templated page, with custom fields and SEO attributes and tagging the page with the Seattle Location ID for use in [Visitor localization](/visitor-localization-sdk/visitor-localization-sdk.md)

`POST /api/v2/pages/`

```json
{
	"active": true,
	"custom_fields": {
		... custom field values based on fields and associated field slugs ...
		"field_1": "value_1",
        "field_2": "value_2",
        "html_field": "<p>value_1<img src=\"https://example.com/image.jpg\" /></p>",
        "related_datamodel_field": [
            {
                "title": "value_1",
                "description": "value_2",
                "image": "https://example.com/image.jpg"
            },
            {
                "title": "value_1",
                "description": "value_2",
                "image": "https://example.com/image.jpg"
            },
        ]
	},
	"custom_page_type": "areas_we_service",
	"locations": [54321],
	"meta_description": "We service the greater Seattle area with top quality services",
	"name": "Seattle",
	"path": "/areas-we-service/seattle/",
	"site_id": 12345,
	"title": "Seattle - Areas we service",
	"type": "template_page"
}
```

## Custom pages (`default` page type)

For Standard `default` pages that use our standard components and blocks to build the page, modules/components are how each block on the page is defined.

On initial page creation, you can send the nested `content` value for `embed` (HTML code) blocks

```json
{
  "column_widths": [[100], [100]],
  "modules": [
    {
      "module": "googlemaps",
      "column": 1,
      "order": 1,
      "row": 1
    },
    {
      "module": "embed",
      "column": 1,
      "order": 1,
      "row": 2,
      "content": "<script src="..."></script>",
      "props": {
        "render_template": true
      }
    }
  ]
  ...
}
```
