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
// Nunjucks also needs an additional path configuration
162
-
// to use the templates and macros from `govuk-frontend`
163
-
const environment = nunjucks.configure(
164
-
[
165
-
...path,
166
-
'node_modules/govuk-frontend/dist'
167
-
]
168
-
)
169
-
170
-
// Applies custom filters and globals for nunjucks
171
-
// that are required by the `forms-engine-plugin`
172
-
prepareNunjucksEnvironment(environment)
173
-
174
-
options.compileOptions.environment = environment
175
-
176
-
return next()
177
-
}
178
-
}
179
-
},
180
-
path,
181
-
context
182
-
}
183
-
})
184
-
185
-
// Registers the `forms-engine-plugin`
122
+
// Register the `forms-engine-plugin`
186
123
await server.register({
187
124
plugin
188
125
})
@@ -201,7 +138,11 @@ The forms plugin is configured with [registration options](https://hapi.dev/api/
201
138
-`formSubmissionService` - used prepare the form during submission (ignore - subject to change)
202
139
-`outputService` - used to save the submission
203
140
-`controllers` (optional) - Object map of custom page controllers used to override the default. See [custom controllers](#custom-controllers)
204
-
-`cacheName` (optional) - The cache name to use. Defaults to hapi's [default server cache]. Recommended for production. See [here](#custom-cache) for more details
141
+
-`filters` (optional) - A map of custom template filters to include
142
+
-`cacheName` (optional) - The cache name to use. Defaults to hapi's [default server cache]. Recommended for production. See [here]
143
+
(#custom-cache) for more details
144
+
-`pluginPath` (optional) - The location of the plugin (defaults to `node_modules/@defra/forms-engine-plugin`)
145
+
205
146
206
147
### Services
207
148
@@ -211,6 +152,25 @@ TODO
211
152
212
153
TODO
213
154
155
+
### Custom filters
156
+
157
+
Use the `filter` plugin option to provide custom template filters.
158
+
Filters are available in both [nunjucks](https://mozilla.github.io/nunjucks/templating.html#filters) and [liquid](https://liquidjs.com/filters/overview.html) templates.
159
+
160
+
```
161
+
const formatter = new Intl.NumberFormat('en-GB')
162
+
163
+
await server.register({
164
+
plugin,
165
+
options: {
166
+
filters: {
167
+
money: value => formatter.format(value),
168
+
upper: value => typeof value === 'string' ? value.toUpperCase() : value
169
+
}
170
+
}
171
+
})
172
+
```
173
+
214
174
### Custom cache
215
175
216
176
The plugin will use the [default server cache](https://hapi.dev/api/?v=21.4.0#-serveroptionscache) to store form answers on the server.
@@ -321,3 +281,21 @@ There are a number of `LiquidJS` filters available to you from within the templa
321
281
}
322
282
]
323
283
```
284
+
285
+
## Templates and views: Extending the default layout
286
+
287
+
TODO
288
+
289
+
To override the default page template, vision and nunjucks both need to be configured to search in the `forms-engine-plugin` views directory when looking for template files.
290
+
291
+
For vision this is done through the `path`[plugin option](https://github.com/hapijs/vision/blob/master/API.md#options)
292
+
For nunjucks it is configured through the environment [configure options](https://mozilla.github.io/nunjucks/api.html#configure).
293
+
294
+
The `forms-engine-plugin` path to add can be imported from:
295
+
296
+
`import { VIEW_PATH } from '@defra/forms-engine-plugin'`
297
+
298
+
Which can then be appended to the `node_modules` path `node_modules/@defra/forms-engine`.
299
+
300
+
The main template layout is `govuk-frontend`'s `template.njk` file, this also needs to be added to the `path`s that nunjucks can look in.
0 commit comments