According to the developer guide “Using Core Modul...
# suitecommerce
c
According to the developer guide “Using Core Modules in Extensibility API Methods*”* (https://developers.suitecommerce.com/build-sustainable-and-stable-extensions.html) the “layout component” will return a console warning. Using the “simple” syntax, what is best practice to add multiple childviews to the ’Home.View”? If I follow the addChildView method outlined in the Frontend Extensibility API docs I get the console warning. https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/Layout.html
s
I assume you refer to this section:
This is because the layout component does not ‘own’ this parent view. Using the code in this second example will result in the following console warning:
This refers to specific scenarios where you try to use verbose syntax with the layout container that are not in its child view chain
c
I am
s
For example, you should not use Layout.addChildViews() with PDPs
If you're referring to the homepage, I don't see why it would return an error or warning. Is that what you're saying -- you've tried it and it's returning an error?
c
Returns the warning mentioned in the help guide.
Copy code
INVALID_PARAM Invoking the method "addChildViews" with an incorrect parameter: (Header.View).
It will still work but it will be deprecated in the future. Please check the documentation.
Copy code
var layout = container.getComponent('Layout');
				
layout.addChildViews('Home.View', {
	'HomeSlider': { 
		'HomeSlider.View': {
			childViewIndex: 1,
			childViewConstructor: function HomeSlider() {
				return new HomeSliderView({
					environment: environment
				});
			}
		}
	}
});
s
OK, well I know why it's returning the warning. It's set up to check if the view you're adding to is Backbone.View, which in your case it obviously isn't
c
Also the HomeSlider.View has been updated to SCView.
So the warning is a SCS bug?
s
Also the HomeSlider.View has been updated to SCView
Not sure that's relevant.
So the warning is a SCS bug?
Hard to say. It makes sense for all the other visual components but not for layout, as one would never add a child view to Backbone.View directly. Equally, how would we expect developers to use addChildViews() with Home.View and Header.View etc?
c
@Steve Goldberg this is the exact code. The following throws a warning in the console. Is it possible to add child views to the existing Home.View without throwing the warning?
Copy code
var layout = container.getComponent('Layout'),
	environment = container.getComponent('Environment')
	
layout.addChildViews('Home.View', {
	'HomeSlider': {
		'HomeSlider.View': {
			childViewIndex: 1,
			childViewConstructor: function intHomeSlider() {
				return new HomeSliderView({
					environment: environment
				});
			}
		}
	}
});
s
Yes, you use the simple syntax instead
Although I wasn't aware our default homepage template has any placeholders to inject child views in. I assume you've added some, or are using some non-default template?
c
We have added placeholders. Edited the template.
@Steve Goldberg - The following appears to work without the warning.
Copy code
var layout = container.getComponent('Layout'),
	environment = container.getComponent('Environment')
layout.addChildViews(
	layout.ALL_VIEWS, {
	'HomeSlider': {
		'Home.View': {
			childViewIndex: 1,
			childViewConstructor: function intHomeSlider() {
				return new HomeSliderView({
					environment: environment
				});
			}
		}
	}
});
s
Yes it will because ALL_VIEWS will return Backbone.View
This is why it may or may not be a bug
Because one of the benefits of using the verbose method is a more specific targeting of the class you want to add your child view to