From 3066d30eff1f71165d9d45e846fa00ef0a1a09d6 Mon Sep 17 00:00:00 2001 From: Max Moroz <95914987+bc-max@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:21:59 +0200 Subject: [PATCH] fix(storefront): strf-10231 Mapped URLs do not use their respective templates: (#1028) - template path lookup refactored; --- server/plugins/renderer/renderer.module.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/plugins/renderer/renderer.module.js b/server/plugins/renderer/renderer.module.js index 4d11c2b7..d5cc8ccb 100644 --- a/server/plugins/renderer/renderer.module.js +++ b/server/plugins/renderer/renderer.module.js @@ -133,7 +133,6 @@ internals.getResponse = async (request) => { ? JSON.parse(await readFromStream(response.data)) : response.data; - internals.updateTemplatePath(request.path, bcAppData); // cache response cache.put( requestSignature, @@ -273,7 +272,7 @@ internals.parseResponse = async (bcAppData, request, response, responseArgs) => internals.getResourceConfig = (data, request, configuration) => { const missingThemeSettingsRegex = /{{\\s*?theme_settings\\..+?\\s*?}}/g; let resourcesConfig = {}; - const templatePath = data.template_file; + const templatePath = internals.getTemplatePath(request.path, data); // If the requested template is not an array, we parse the Frontmatter // If it is an array, then it's an ajax request using `render_with` with multiple components @@ -337,9 +336,9 @@ internals.redirect = async (response, request) => { * * @param {string} requestPath * @param {Object} data - * @returns {void} + * @returns {string} */ -internals.updateTemplatePath = (requestPath, data) => { +internals.getTemplatePath = (requestPath, data) => { const customLayouts = internals.options.customLayouts || {}; const pageType = data.page_type; let templatePath; @@ -362,10 +361,9 @@ internals.updateTemplatePath = (requestPath, data) => { if (templatePath) { templatePath = path.join('pages/custom', pageType, templatePath.replace(/\.html$/, '')); - // eslint-disable-next-line no-param-reassign - data.template_file = templatePath; } } + return templatePath || data.template_file; }; function getAcceptLanguageHeader(request) { @@ -406,7 +404,7 @@ internals.getPencilResponse = (data, request, response, configuration, renderedR return new PencilResponse( { - template_file: data.template_file, + template_file: internals.getTemplatePath(request.path, data), templates: data.templates, remote: data.remote, remote_data: data.remote_data,