Skip to content

Commit

Permalink
Hook custom control into FE Templating process
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Önnheim committed Nov 28, 2023
1 parent add7347 commit ab2fa8d
Show file tree
Hide file tree
Showing 3 changed files with 896 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/featureShowcase/webapp/Component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sap.ui.define(['sap/fe/core/AppComponent'], function(AppComponent) {
sap.ui.define([
'sap/fe/core/AppComponent',
'sap/fe/featureShowcase/mainApp/control/FeatureShowcaseChildEntity2', // To ensure the custom control is loaded during templating
], function(AppComponent) {
'use strict';

return AppComponent.extend("sap.fe.featureShowcase.mainApp.Component", {
Expand Down
44 changes: 44 additions & 0 deletions app/featureShowcase/webapp/control/FeatureShowcaseChildEntity2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
sap.ui.define([
'sap/m/Link',
'sap/fe/macros/field/FieldTemplating',
'sap/m/MessageBox',
], function (
Link,
FieldTemplating,
MessageBox,
) {
'use strict';

return Link.extend("sap.fe.featureShowcase.mainApp.control.FeatureShowcaseChildEntity2", {
metadata: {
manifest: "json"
},
renderer: {},

// Implement the interface dictated by the templating process
getTemplate: function (xml, internalField) {
const text = FieldTemplating.getTextBinding(internalField.dataModelPath, internalField.formatOptions, true);

return xml`<myApp:FeatureShowcaseChildEntity2
xmlns="sap.m"
xmlns:myApp="sap.fe.featureShowcase.mainApp.control"
xmlns:core="sap.ui.core"
id="${internalField.noWrapperId}"
text="${text}"
visible="${internalField.displayVisible}"
wrapping="${internalField.wrap === undefined ? true : internalField.wrap}"
ariaLabelledBy="${internalField.ariaLabelledBy}"
emptyIndicatorMode="${internalField.emptyIndicatorMode}"
customData:loadValue="${internalField.valueAsStringBindingExpression}"
>
</myApp:FeatureShowcaseChildEntity2>`;
},

//
init: function () {
this.attachPress(oEvent => {
MessageBox.show('I am a custom control, injected in a FE template');
});
},
});
});

0 comments on commit ab2fa8d

Please sign in to comment.