You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(docs): PLUGIN_OPTIONS documentation with required and optional options, including detailed explanations for nunjucks configuration, viewContext, and model usage. Add examples for clarity. (#221)
Copy file name to clipboardExpand all lines: docs/PLUGIN_OPTIONS.md
+158-7Lines changed: 158 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,21 +9,29 @@ nav_order: 3
9
9
10
10
The forms plugin is configured with [registration options](https://hapi.dev/api/?v=21.4.0#plugins)
11
11
12
+
## Required options
13
+
14
+
-`nunjucks` (required) - Template engine configuration. See [nunjucks configuration](#nunjucks-configuration)
15
+
-`viewContext` (required) - A function that provides global context to all templates. See [viewContext](#viewcontext)
16
+
-`baseUrl` (required) - Base URL of the application (protocol and hostname, e.g., `"https://myservice.gov.uk"`). Used for generating absolute URLs in markdown rendering and other contexts
17
+
18
+
## Optional options
19
+
20
+
-`model` (optional) - Pre-built `FormModel` instance. When provided, the plugin serves a single static form definition. When omitted, forms are loaded dynamically via `formsService`. See [model](#model)
12
21
-`services` (optional) - object containing `formsService`, `formSubmissionService` and `outputService`
13
22
-`formsService` - used to load `formMetadata` and `formDefinition`
14
23
-`formSubmissionService` - used prepare the form during submission (ignore - subject to change)
15
24
-`outputService` - used to save the submission
16
25
-`controllers` (optional) - Object map of custom page controllers used to override the default. See [custom controllers](#custom-controllers)
17
-
-`globals` (optional) - A map of custom template globals to include
18
-
-`filters` (optional) - A map of custom template filters to include
19
-
-`cache` (optional) - Caching options
20
-
-`cache` (optional) - Caching options. Recommended for production. This can be either:
21
-
- a string representing the cache name to use (e.g. hapi's default server cache). See [here](#custom-cache) for more details.
22
-
- a custom `CacheService` instance implementing your own caching logic
26
+
-`globals` (optional) - A map of custom template globals to include. See [custom globals](#custom-globals)
27
+
-`filters` (optional) - A map of custom template filters to include. See [custom filters](#custom-filters)
28
+
-`cache` (optional) - Caching options. Recommended for production. This can be either:
29
+
- a string representing the cache name to use (e.g. hapi's default server cache). See [custom cache](#custom-cache) for more details.
30
+
- a custom `CacheService` instance implementing your own caching logic
23
31
-`pluginPath` (optional) - The location of the plugin (defaults to `node_modules/@defra/forms-engine-plugin`)
24
32
-`preparePageEventRequestOptions` (optional) - A function that will be invoked for http-based [page events](./features/configuration-based/PAGE_EVENTS.md). See [here](./features/configuration-based/PAGE_EVENTS.md#authenticating-a-http-page-event-request-from-dxt-in-your-api) for details
25
33
-`saveAndExit` (optional) - Configuration for custom session management including key generation, session hydration, and persistence. See [save and exit documentation](./features/code-based/SAVE_AND_EXIT.md) for details
26
-
-`onRequest` (optional) - A function that will be invoked on each request to any form route e.g `/{slug}/{path}`. See [here](#onrequest) for more details
34
+
-`onRequest` (optional) - A function that will be invoked on each request to any form route e.g `/{slug}/{path}`. See [onRequest](#onrequest) for more details
27
35
28
36
## Services
29
37
@@ -33,6 +41,149 @@ See [our services documentation](./features/code-based/CUSTOM_SERVICES.md).
33
41
34
42
TODO
35
43
44
+
## nunjucks configuration
45
+
46
+
The `nunjucks` option is required and configures the template engine paths and layout.
47
+
48
+
```ts
49
+
{
50
+
baseLayoutPath: string// Path to the base layout template
51
+
paths: string[] // Array of paths to search for Nunjucks templates
52
+
}
53
+
```
54
+
55
+
Example:
56
+
57
+
```js
58
+
awaitserver.register({
59
+
plugin,
60
+
options: {
61
+
nunjucks: {
62
+
baseLayoutPath:'layout.html',
63
+
paths: [
64
+
'src/server/views',
65
+
'node_modules/govuk-frontend/dist'
66
+
]
67
+
}
68
+
}
69
+
})
70
+
```
71
+
72
+
The `baseLayoutPath` is the file that all form pages will extend. The `paths` array tells Nunjucks where to look for templates, including your custom templates and any third-party template libraries (like GOV.UK Frontend).
73
+
74
+
## viewContext
75
+
76
+
The `viewContext` option is a required function that provides global context variables to all templates rendered by the plugin.
This function receives the current request (or `null` for non-request contexts) and should return an object containing any data you want available in your templates, such as:
0 commit comments