# Detail pages and params

## Detail pages

A page with `"sidebar": false` isn't listed in the sidebar. It's the page behind a link: a "Garage door open" card on your home page leads to a Security page with every door and sensor, and Back returns. Link to it from any card that takes a link, with `legato://page/ID` (see [Links to other pages](https://legatobar.com/docs/card-fields.md#links-to-other-pages)), and from as many pages as you like.

```json
{ "title": "Security", "icon": "lock.shield", "sidebar": false, "cards": [ … ] }
```

- Arrived at by a card's link, the title row starts with the way back, named: **‹ Home**. A page [titled by its item](https://legatobar.com/docs/detail-pages.md#titled-by-its-item) is named in it by that item, the one that step goes back to. ⌘[ goes back too, and back on the first page, the cards are scrolled where you left them, with the same tabs and sections open.
- Only navigation changes. A detail page fetches its sources, notifies, and lights the menu bar icon like any other page, and Spotlight and Shortcuts find it, so you can always reach it.
- It can't be the [home page](https://legatobar.com/docs/sections.md#organizing-pages-into-sections): **Open on** lists only sidebar pages, and a home page that becomes a detail page is set aside, as a missing one is, until it's back in the sidebar. With **Last page viewed**, the panel reopens on a detail page if that's where you were.
- Behind a page with a [period](https://legatobar.com/docs/periods.md#periods), give it the same choices: a link opens it on the period the overview shows. See [Overview and detail pages with a period](https://legatobar.com/docs/design.md#overview-and-detail-pages-with-a-period).
- `legato list` and `list_pages` mark it with `"sidebar": false`. To list it in the sidebar again, take the key out or set it to `true`.

### One page for every item

When every item of a fleet gets the same detail page (each guest on a server, each project in a to-do app), write the page once with `params`, and let each item's link say which one it's showing. Legato fills the values in wherever the page says `{param.name}`: a source's requests, a button's path and body, a card's text and the title.

<figure class="docs-figure">
<img class="is-light" src="/docs/one-page-for-every-item-light.png" width="720" height="332" alt="A Todoist project page in Legato, titled Home, beside the page file it comes from. The file's tasks request ends in {param.project}, and a line runs from project = 6Jf8Hm, Home, to the page's title.">
<figcaption>One file, every project: the link that opens Home sets <code>project</code>, and <code>{param.project}</code> in the page's request fills with it. Launch's link opens the same page with Launch's tasks.</figcaption>
</figure>

```json
{ "title": "Guest", "icon": "server.rack", "sidebar": false,
  "params": { "vmid": { "type": "integer", "example": "100" } },
  "sources": { "guest": { "url": "https://pve.example.com", "secret": "proxmox",
    "requests": { "status": "/api2/json/nodes/pve/qemu/{param.vmid}/status/current" } } },
  "cards": [ … ] }
```

The link names the value: `legato://page/proxmox-vm?vmid=109`. A fleet or bars row maps it from its source, as `"url": { "template": "legato://page/proxmox-vm?vmid={vmid|raw}" }`, so a guest added later has a working page at once.

| Field | | |
| --- | --- | --- |
| `type` | optional | `string` (the default) or `integer`: digits only, and a string that is the token alone, such as a request body's `"vmid": "{param.vmid}"`, becomes the number. |
| `pattern` | optional | A regular expression the whole value must match, such as `[0-9]{3}`. |
| `type: "text"` | optional | A name of 1 to 40 characters. Allows letters in any script, digits, spaces and `. , ' - ( ) &`. No leading or trailing spaces. |
| `type: "query"` | optional | What someone typed to search for, from a [form that opens a page](https://legatobar.com/docs/button-input.md#forms-that-open-a-page): 1 to 200 characters on one line, anything but `{`, `}`, tabs, other control characters and marks that reverse the reading order, such as `tag:bills "late fee"`. No leading or trailing spaces. |
| `example` | required | The value the page is checked with when no link gives one: by `legato set`, `--validate-page` and the Source Preview window. |
| `list_key` | optional | A list's name: the value is a host's key on that list, for [a page about one host](https://legatobar.com/docs/source-requests.md#a-page-for-one-host-on-the-list) of a host list. No `type`, `pattern` or `default`. |
| `selects` | optional | `true` when the value picks something on the page, such as a row of its list, rather than another item. While the page reads again for a new value, it draws at once from its last answer: cards that don't read what the value changes stay as they are, and the rest show their last shape in grey until their answer is back. Pi-hole's Queries page takes the query you click this way. |

- **A value is checked before it's used.** A link can come from any app. A string or integer value is 1 to 64 letters, digits, `.`, `_`, `~` and `-`, and matches the parameter's type and pattern. A string parameter with its own `pattern` may also take `:` and up to 128 characters, for ids like a UniFi console's (`900A…:123456789`): the colon goes into a request's path or query as `%3A`, and into a body as written. One that doesn't is refused, so it can't reach another route or another field.
- **Up to four** params, named with lowercase letters, digits and `_`. A link gives them as `?name=value&name=value`, each once; names the page doesn't take are ignored.

For a place name, declare `"name": { "type": "text", "example": "Lake cabin" }` in `params`. Open it with `legato://page/open-meteo?name=Lake%20cabin`. A title of `"{param.name}"` shows `Lake cabin`. Text values are decoded from the link and checked. They are percent-encoded when filled into request URLs. `pattern` and `default` work for text too. A `query` value is handled the same way: decoded from the link, checked, percent-encoded in request URLs, and filled in as it was typed everywhere else, such as a title of `"{param.q}"`.

- **Without defaults, opened without acceptable values** (from a link that names none, or a value it refuses), the page shows only a line saying it opens from a link. Nothing is fetched.
- **Without defaults it sets no light and posts no notification,** since what it shows depends on the link: the page that lists the items watches them. Its buttons stay in the panel, and aren't offered to Spotlight or Shortcuts, which would press one without saying which item it's for.
- A name with spaces or emoji can't travel in a link, so put an id in the link and let the page take its name from the source with [`title_from`](https://legatobar.com/docs/detail-pages.md#titled-by-its-item).
- **The icon can come from a param too:** `"icon": "{param.icon}"` for an SF Symbol (`?icon=server.rack`), or `"icon": "si:{param.brand}"` for a logo, the prefix written in the page since a value can't hold `:`. Opened without values, the page shows Legato's default icon.
- Parameterized pages remember the item in Back and Forward history. Background Shortcuts reads do not accept an item parameter yet, so Get Card Value and page summaries read the defaults when present and otherwise refuse these pages. Parameter values cannot be `.` or `..`.

#### A default item

Give every param a `default` to make one item the page's home. Each default must pass the same type and pattern checks as a link value. Give every param a default, or none.

```json
{ "title": "Weather",
  "params": {
    "lat": { "example": "33.44", "default": "33.44" },
    "lon": { "example": "-94.04", "default": "-94.04" }
  },
  "sources": { "weather": {
    "url": "https://api.openweathermap.org",
    "secret": "openweather", "auth": { "type": "query", "name": "appid" },
    "requests": { "one": "/data/3.0/onecall?lat={param.lat}&lon={param.lon}&units=imperial" }
  } },
  "cards": [{ "id": "temperature", "type": "stat", "label": "Temperature", "value": 0,
    "source": { "ref": "weather", "map": { "value": "one.current.temp" } } }]
}
```

This page can stay in the sidebar. Opening it there, in Spotlight or from a link without values shows the defaults. The default item fetches on schedule, counts in the Dock badge, posts notifications and offers buttons to Spotlight and Shortcuts.

A link with other values shows that item in the panel. It sets no light and posts no notification. The default item keeps fetching and watching in the background. A link with the default values returns home too. Shortcuts and external buttons always use the default item.

#### Titled by its item

`title_from` names the panel's title row from a source's answer: the monitor, guest or package the link opened. `ref` names one of the page's sources, and `value` is a [rule](https://legatobar.com/docs/mapping.md#mapping), read against that source's answer as a card's `map` is:

```json
{ "title": "Monitor", "sidebar": false,
  "params": { "id": { "type": "integer", "example": "1" } },
  "title_from": { "ref": "kuma", "value": { "first": "monitor_name", "of": "monitors",
                                            "where": { "path": "monitor_id", "equals": "{param.id}" } } },
  "sources": { "kuma": { "url": "https://status.example.com", "secret": "kuma", "auth": { "type": "basic" },
    "requests": { "monitors": { "path": "/metrics", "format": "prometheus", "group_by": "monitor_id" } } } },
  "cards": [ … ] }
```

Opened from `legato://page/uptime-monitor?id=4`, the title row says **Git** once the source answers, and **Monitor** until then.

- **`title` is the fallback.** It shows before the first answer, when the rule gives nothing (no monitor 4, a field the answer lacks, a template missing any of its values), and while the source needs access. A source that stops answering keeps the last name it gave.
- **One line of plain text,** up to 60 characters: line breaks become spaces, and a longer name ends in "…". Nothing in it is read as a link or markdown.
- **The title row, the Back trail and notifications** use it. The sidebar, Settings, Spotlight and Shortcuts, `legato list` and `list_pages` keep `title`, the page's own name; renaming the page with **Edit…** changes `title`.
- **It reads the source on its own,** sharing the fetch with the cards that use the same source, so a card that's hidden or has a mistake doesn't change the name. On a page with a [period](https://legatobar.com/docs/periods.md#periods), the source is read for the first choice, the default, as status cards are: the name doesn't change with the period showing.
- Any page can have one, but it's for a page about one item; a page about a whole service keeps a written title. It can't name a history (a `dataset` source).



## Views

A page and its siblings can show as tabs under one title, as Tesla's Overview, Drives and Charges do. The leading page lists them once, itself among them:

```json
"views": [ { "page": "tesla", "label": "Overview" }, { "page": "tesla-trips", "label": "Drives" }, { "page": "tesla-charging", "label": "Charges" } ]
```

- Each view stays its own page, with its own file, sources, layout, period and params, so `legato://page/tesla-trips` opens the Drives tab.
- The sidebar shows the leading page alone and keeps it selected on any of its views. The title row keeps the leading page's name, icon and title-row controls on every view, and the tabs sit under it, underlined.
- 2 to 8 views, each page once, labels of 1 to 24 characters. A view whose page isn't there is left out of the tabs.
- The tabs are drawn on pages with `"look": "sheet"` in the window. Give each view a sheet layout.
