` and heading; `description` its meta description. Give them here, not in the
template: the controller writes them after the page has run.
The overview lists the other pages of its folder. It reads them from the page tree rather than writing them a
second time, in `src/pages/services/overview.phtml`:
```php from=src/pages/services/overview.phtml
$content = $_VARS['controller']->getMainContent();
?>
= htmlspecialchars($content->getTitle()) ?>
```
A page is plain php, run with two things in scope: `$this`, the html document being built, and `$_VARS`, its
variables. `$_VARS['route']` is the request, `$_VARS['controller']` the PageController serving it. They are not
separate variables: write `$_VARS['route']`, never `$route`.
## 3. One template, several pages
Consulting and Support are the same page with other values. Name the template with `file`, and put what differs
in `data`:
```json from=src/pages/services/index.json
"consulting": {
"label": "Consulting",
"title": "Consulting",
"description": "An Acme engineer, on your project.",
"file": "service.phtml",
"data": {"rate": 900, "unit": "day"}
},
```
`support` is the same with `"rate": 300, "unit": "month"`. In the template, each key of `data` is in `$_VARS`:
`$_VARS['rate']`. Keep `data` to names of your own: a key named `route`, `controller`, `document` or `app` would
hide the one the page needs.
## 4. Reading the request, answering an error
`src/pages/services/service.phtml` reads the quantity from the url, `services/consulting?quantity=3`:
```php from=src/pages/services/service.phtml
$route = $_VARS['route'];
$content = $_VARS['controller']->getMainContent();
$quantity = (int)$route->get('quantity', 1);
```
A wrong value is answered with its status. Throwing an exception in a page does not do that: the page catches
it and prints it in its place, with a 200. Change the response's status instead, then `return` to end the page:
```php from=src/pages/services/service.phtml
setResponse($route->getResponse()->withStatus(422)); ?>
The quantity must be 1 or more.
```
A url that no page matches, `services/training`, is a 404 already: the controller answers it before any page
runs.
## 5. Parts
The price is a part: a `.phtml` that no `index.json` names, so it is no page, imported by the pages that need it.
`src/pages/services/parts/price.phtml`:
```php from=src/pages/services/parts/price.phtml
$total = $_VARS['rate'] * $_VARS['quantity'];
?>
= $_VARS['quantity'] ?> = htmlspecialchars($_VARS['unit']) ?>(s) × = number_format($_VARS['rate']) ?> € = = number_format($total) ?> €
```
The service page imports it with its own variables:
```php from=src/pages/services/service.phtml
= $this->import('services/parts/price.phtml', ['rate' => $_VARS['rate'], 'unit' => $_VARS['unit'], 'quantity' => $quantity], false) ?>
```
Two things to know about `import()`:
- **The name is relative to the pages folder**, not to the calling file: `services/parts/price.phtml` from any page.
- **`false` returns the html**, which the page echoes where it stands. Without it, the part is added to the end of
the document, below the whole page.
## 6. Try it, then test it
: the menu has a Services category with its three pages, and the overview links to
the other two. shows `3 day(s) × 900 € = 2,700 €`.
`tests/unit/TestServices.php`:
```php from=tests/unit/TestServices.php
public function testOneTemplateServesBothPagesWithTheirData(): void {
$this->assertStringContainsString('2,700 €', (string)$this->http('GET', 'services/consulting?quantity=3')->getBody());
$this->assertStringContainsString('300 €', (string)$this->http('GET', 'services/support')->getBody());
}
public function testAWrongQuantityIs422AndAnUnknownPage404(): void {
$this->assertSame(422, $this->http('GET', 'services/support?quantity=0')->getStatusCode());
$this->assertSame(404, $this->http('GET', 'services/training')->getStatusCode());
}
```
```bash
phpunit
```
## Common mistakes
- **`= $value ?>` with a value from outside the file.** A page prints raw html: escape text with
`htmlspecialchars()`.
- **`setTitle()` in a page.** The controller writes the title after the page: give `title` in `index.json`.
- **`throw new e404(...)` in a page.** It shows the error inside a 200. Set the status on the response.
- **`$this->import('parts/price.phtml')` without `false`.** The part lands below the page, not where it is called.
- **`'../parts/price.phtml'`.** A part's name is relative to the pages folder, whatever page calls it.
## Going further
- Next: **Your first controller**, for what a page should not do: an API.
- [Pages](https://www.mmoframework.fr/en/documentation/mmo.client/Pages.md): every key of `index.json`, the menu,
the shell's regions and layouts, forms posting to their page, error pages.