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 003893b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,23 @@ function locateTemplateConfig (req) {
}
}

function getTemplatesViewHandler (req, res) {
const model = {
pluginConfig: plugins.getAppConfig({ scripts: prototypeAppScripts }),
serviceName: 'Service name goes here'
}
function getTemplatesViewHandler(req, res) {
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 003893b

Please sign in to comment.