Skip to content

Commit

Permalink
Merge pull request #1346 from sacr3dc0w/custom-module-mapping
Browse files Browse the repository at this point in the history
Blueprint for Mapping Custom Templates to JavaScript Modules
  • Loading branch information
junedkazi authored Sep 19, 2018
2 parents 200e190 + 287ebe7 commit b4fafff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Blueprint for Mapping Custom Templates to JavaScript Modules [#1346](https://github.com/bigcommerce/cornerstone/pull/1346)

## 2.4.0 (2018-09-14)
- Fix encoding issues on Account Signup Form ("'" characters showing in country name)[#1341] (https://github.com/bigcommerce/cornerstone/pull/1341)
Expand Down
13 changes: 13 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const pageClasses = {
wishlists: () => import('./theme/wishlist'),
};

const customClasses = {};

/**
* This function gets added to the global window and then called
* on page load with the current template loaded and JS Context passed in
Expand All @@ -59,6 +61,8 @@ const pageClasses = {
*/
window.stencilBootstrap = function stencilBootstrap(pageType, contextJSON = null, loadGlobal = true) {
const context = JSON.parse(contextJSON || '{}');
const template = context.template;
const templateCheck = Object.keys(customClasses).indexOf(template);

return {
load() {
Expand All @@ -74,6 +78,15 @@ window.stencilBootstrap = function stencilBootstrap(pageType, contextJSON = null
const PageClass = (await pageClassImporter()).default;
PageClass.load(context);
}

if (templateCheck > -1) {
// Find the appropriate page loader based on template
const customClassImporter = customClasses[template];
if (typeof customClassImporter === 'function') {
const CustomClass = (await customClassImporter()).default;
CustomClass.load(context);
}
}
});
},
};
Expand Down
1 change: 1 addition & 0 deletions templates/layout/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{{inject 'genericError' (lang 'common.generic_error')}}
{{inject 'maintenanceMode' settings.maintenance}}
{{inject 'urls' urls}}
{{inject 'template' template}}
{{{snippet 'htmlhead'}}}
</head>
<body>
Expand Down

0 comments on commit b4fafff

Please sign in to comment.