From 003893bc94a6ffe008bf7cadf021bdae33431071 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Wed, 21 Feb 2024 21:44:21 +0000 Subject: [PATCH] Add GOV.UK Frontend path locals to template previews Fixes https://github.com/alphagov/govuk-prototype-kit/issues/2392 --- lib/manage-prototype-handlers.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/manage-prototype-handlers.js b/lib/manage-prototype-handlers.js index bfd51f90fd..6ffc0e7f48 100644 --- a/lib/manage-prototype-handlers.js +++ b/lib/manage-prototype-handlers.js @@ -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.') }