Skip to content

Commit

Permalink
Add GOV.UK Frontend path locals to template previews
Browse files Browse the repository at this point in the history
Fixes #2392
  • Loading branch information
colinrotherham committed Feb 21, 2024
1 parent 1a5c016 commit 5acf2a4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,22 @@ function locateTemplateConfig (req) {
}

function getTemplatesViewHandler (req, res) {
const model = {
pluginConfig: plugins.getAppConfig({ scripts: prototypeAppScripts }),
serviceName: 'Service name goes here'
}
const templateConfig = locateTemplateConfig(req)

// Nunjucks environment for template previews uses `getAppViews()` to
// add plugins including GOV.UK Frontend views via project package
const nunjucksAppEnv = nunjucksConfiguration.getNunjucksAppEnv(appViews)

// Use GOV.UK Frontend paths from Express.js locals
const { govukFrontend, govukFrontendInternal } = req.app.locals

if (templateConfig) {
res.send(nunjucksAppEnv.render(templateConfig.path, model))
res.send(nunjucksAppEnv.render(templateConfig.path, {
govukFrontend,
govukFrontendInternal,
pluginConfig: plugins.getAppConfig({ scripts: prototypeAppScripts }),
serviceName: 'Service name goes here'
}))
} else {
res.status(404).send('Template not found.')
}
Expand Down

0 comments on commit 5acf2a4

Please sign in to comment.