Adding content to existing pages by using extension points
Every component that makes up a page contains 2 extension points (top and bottom) for inserting custom code into any existing page. Use the differential customization approach to add content to Order Hub existing pages by using these extension points.
Consider using this differential customization approach for your customizations over the customization by overrides approach, as your updates are preserved when Order Hub releases updates to the same pages that you customized. No code merge is required; simply recompile with the monthly DTK code.
Before you begin
- Go to the Order Hub page that you want to add content to.For example, the order details page:
- Show the extension points available for you to add content to on the page.
- Press Ctrl + D to show the available extension points on the page.Each page component contains extension points denoted by the following label and naming convention:
Optional custom component can be placd here. Component name: ComponentName Identifier: ID
For example, the order details page extension points: - Make note of the identifiers of the extension points that you want to add content to.
- Press Ctrl + Shift + D to hide the available extension points on the page.
- Press Ctrl + D to show the available extension points on the page.
Then, make your updates to add content to existing pages by using extension points:
Procedure
Results
As a reference, the following tutorial adds content to existing pages by using extension points: Tutorial: Customizing the Schedule order action.
Example
- Identify the extension directive that will be used to insert your customizations. Each default
Angular component will have extension directives at the beginning and end of the component. For
example:
<ng-template bucExtension [componentName]="componentName" [placement]="'top'" [id]="id" [parent]="this"> </ng-template>
Each of these templates will have unique IDs defined in the packages/order-details/src/app/features/order/order-details/order-details.component.ts file:EXTENSION = { TOP: ExtensionConstants.ORDER_DETAILS_TOP, BOTTOM: ExtensionConstants.ORDER_DETAILS_BOTTOM };
These constants are defined in the packages/order-details/src/app/features/order/extension.constants.ts file:export class ExtensionConstants { static readonly ORDER_DETAILS_TOP = 'order_details_extension_top'; static readonly ORDER_DETAILS_BOTTOM = 'order_details_extension_bottom'; }
- Create a new component that has to be injected. For example:
import { Component, EventEmitter, Input, Output } from '@angular/core'; @Component({ selector: 'custom-orderdetails-extension', template: '' }) export class CustomOrderDetailsExtensionComponent{ }
Update the declarations array in the packages/order-details/src-custom/app/app-customization.impl.ts file:import { CustomOrderDetailsExtensionComponent } from "./features/order/custom-order-details-extension/custom-order-details-extension.component" ... static readonly components = [CustomOrderDetailsExtensionComponent];
- Create a new service to handle the parent-child communication:
import { Injectable, OnDestroy } from "@angular/core"; import { BucNotificationModel, BucNotificationService } from '@buc/common-components'; import { ExtensionService } from "./extension.service"; @Injectable() export class CustomOrderDetailsExtensionService extends ExtensionService implements OnDestroy { userInputs = { name: ''} constructor( public bucNotificationService: BucNotificationService) { super(); } createInput() { // check only the necessary properties for update if (this.parentContext.name !== this.userInputs.name) { this.userInputs.name = this.parentContext.name; } this.userInputObs$.next(this.userInputs); } handleOutput() { this.userOutputs = { changesEmitted: this.onChangesEmitted.bind(this) } this.userOutputObs$.next(this.userOutputs); } onChangesEmitted(event: any) { this.bucNotificationService.send([ new BucNotificationModel({ statusType: 'success', statusContent: `Message emitted from dynamic component: ${event.message}` }) ]); } }
- Update the app-customization.impl.ts file as follows:
... import { CustomOrderDetailsExtensionService } from "./services/custom-order-details-extension-service" import { ExtensionConstants } from "./features/order/extension.constants"; import { ExtensionModule } from "@buc/common-components"; ... static readonly imports = [ ExtensionModule.forRoot( [{ id: ExtensionConstants.DETAILS_TAB_BOTTOM, component: CustomOrderDetailsExtensionComponent, service: CustomOrderDetailsExtensionService }]) ]; ...