# Collection views

`view` controls how a collection's entries are listed. Without it, SP CMS lists each entry by its primary field.

```yaml
- name: posts
  type: collection
  path: src/content/posts
  view:
    fields: [title, author.name, date, draft]
    primary: title
    sort: [date, title]
    search: [title, tags]
    default:
      sort: date
      order: desc
```

## Keys

| Key              | Description                                                                                                                                                                                                              |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `fields`         | Columns to show, in order. Use dots for nested fields, such as `author.name`.                                                                                                                                            |
| `primary`        | The field used as each entry's label and for `{primary}` in [filenames](/configuration/content/filename/). Defaults to `title`, `name` or `label`, then the first string, text, number or date field, then the filename. |
| `sort`           | Fields editors can sort by.                                                                                                                                                                                              |
| `search`         | Fields the search box looks in.                                                                                                                                                                                          |
| `default.sort`   | Field to sort by at first.                                                                                                                                                                                               |
| `default.order`  | `asc` or `desc`.                                                                                                                                                                                                         |
| `default.search` | Search query to start with.                                                                                                                                                                                              |
| `foldersFirst`   | `true` to list folders before entries.                                                                                                                                                                                   |
| `layout`         | `list` (default) or `tree`.                                                                                                                                                                                              |
| `node`           | Tree layout settings; see below.                                                                                                                                                                                         |

## Tree layout

For content kept in nested folders, such as documentation, `layout: tree` shows entries as an expandable tree. Each folder is represented by a node file inside it:

```yaml
view:
  layout: tree
  node:
    filename: index.md
    hideDirs: nodes
```

- `filename`: the file that represents its folder, such as `index.md`.
- `hideDirs`: hide folders that have a node file (`nodes`), folders that don't (`others`), or `all`.

`node: index.md` is shorthand for `{ filename: index.md, hideDirs: nodes }`.
