Skip to content

Commit

Permalink
fix(storefront): strf-10231 Mapped URLs do not use their respective t…
Browse files Browse the repository at this point in the history
…emplates: (#1028)

- template path lookup refactored;
  • Loading branch information
bc-max authored Dec 8, 2022
1 parent 6251cbe commit 3066d30
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions server/plugins/renderer/renderer.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3066d30

Please sign in to comment.