Add Child View to Composite View in SuiteCommerce Advanced
Learn to add a child view to a Composite View in SuiteCommerce Advanced, enhancing functionality with custom modules.
Adding a child view to a parent view is a common way of extending the functionality of SuiteCommerce Advanced (SCA). For example, you can easily add a message to a page by adding a GlobalViews.Message.View view as a child view. Adding a child view requires making two types of changes to the SCA source code:
-
Extend the
childViewsobject of a view. Because this requires a change to a JavaScript or TypeScript source file, you should create a custom module that uses prototyping to add the child view.The module source files for SCA 2019.1 and earlier are JavaScript files with .js filename extensions. The module source files for SCA 2019.2 and later are TypeScript files with .ts filename extensions. For more information about TypeScript, see TypeScript.
-
Override the template file. In addition to adding the view to the
childViewsobject, you must also edit the HTML template to implement the child view in a page.
Note:
Because a template file can only be overridden one time, you may want to define the override in a different custom module created specifically for template overrides when making your own customizations. See Override a Template File for more information.
To extend the childViews object of a view:
-
Create the directory structure for your custom module.
-
Create a directory called
extensions.-
If implementing 2019.2 and later, create this directory in the
Advanceddirectory. Examples:SC_20.1/Advanced/extensions,SC_19.2_Live/Advanced/extensions. -
If implementing 2019.1 and earlier, create this directory in the
Modulesdirectory. For example:Modules/extensions
-
-
In the
extensionsdirectory, create a subdirectory calledHeaderExtension@1.0.0. -
In the
HeaderExtensiondirectory, create a subdirectory calledJavaScript. -
Also in the
HeaderExtensiondirectory, create another subdirectory calledTemplates.
When creating customizations, you should create a directory structure as described in Organize Source Code for Custom Modules.
-
-
Create a new file.
-
If implementing 2019.2 or later, name this file HeaderExtension.ts.
-
If implementing 2019.1 or earlier, name this file HeaderExtension.js.
-
-
Define your custom module and dependencies by adding the following code to this file.
This code defines the dependencies required by your custom module. If implementing SuiteCommerce 2019.1 or earlier, see Asynchronous Module Definitions (AMD) and RequireJS for information about defining dependencies within a module. This module includes the following views as dependencies:
-
Header.View - is required to extend the
childViewsobject. -
GlobalViews.Message.View - is required to add a message view to the application header.
JavaScript example:
javascript1define('HeaderExtension'2, [3 'underscore'4 , 'Header.View'5 , 'GlobalViews.Message.View'6 ]7, function (8 _9 , HeaderView10 , GlobalViewsMessageView11 )12{13 'use strict';1415 //Additional code goes here.1617});TypeScript example:
javascript1///<amd-module name="HeaderExtension"/>23/// <reference path="../../../Commons/Utilities/JavaScript/GlobalDeclarations.d.ts" />45import * as _ from 'underscore';6import HeaderView = require('../../Header/JavaScript/Header.View');7import GlobalViewsMessagesView = require ('../../GlobalViews.Messages.View');89 //Additional code goes here.; -
-
Add the
mountToAppmethod to the Header.Extension.js file (or the Header.Extension.ts file) as shown in the following sample:javascript1return {23 mountToApp: function (application)4 {56 HeaderView.prototype.childViews.HeaderExtension = function()7 {8 return new GlobalViewsMessageView({9 message: 'Hello World! - This is an Example of a GlobalMessageView!'10 , type: 'success'11 , closable: true12 });13 }14 }15}This code performs the following:
-
Specifies a
returnstatement that returns themountToAppmethod. This method is required to load a module into the application. -
Extends the
childViewsobject of the Header.View module using JavaScript prototyping.
-
-
Copy the original template file to your custom module.
-
Copy the header.tpl file to the Templates directory of your custom module.
- If implementing 2019.2 and later, copy
-
Frequently Asked Questions (4)
What is the recommended way to extend the childViews object in SuiteCommerce Advanced?
Where should I create the custom module directory for my extensions in SCA?
Can a template file be overridden more than once in SuiteCommerce?
Do I need to copy the original template file for modifications in SuiteCommerce Advanced?
Was this article helpful?
More in Commerce
- SuiteCommerce CAPTCHA Configuration Options and Setup
Configure SuiteCommerce CAPTCHA for enhanced security. Enable CAPTCHA for registration, login, guest checkout, and orders.
- Single Sign-On Integration for NetSuite Web Stores
Implement inbound single sign-on integration for NetSuite web stores using SAML or OpenID Connect for seamless access.
- Facets Management for Commerce in NetSuite
Facets management in NetSuite Commerce optimizes item search filters, enhancing performance and improving user experience.
- SuiteCommerce Analytics Data and Cookie Consent Integration
SuiteCommerce Analytics Data enables tracking of shopper behavior. This requires a cookie consent extension for user preferences.
Advertising
Reach Commerce Professionals
Put your product in front of NetSuite experts who work with Commerce every day.
Sponsor This Category