|
1 | 1 | ---
|
2 | 2 | title: Build your first SharePoint Framework Extension (Hello World part 1)
|
3 | 3 | description: Create an extension project, and then code and debug your Application Customizer.
|
4 |
| -ms.date: 06/25/2020 |
| 4 | +ms.date: 10/2/2020 |
5 | 5 | ms.prod: sharepoint
|
6 | 6 | localization_priority: Priority
|
7 | 7 | ms.custom: scenarios:getting-started
|
@@ -65,20 +65,64 @@ You can also follow the steps in this article by watching the video on the Share
|
65 | 65 | 1. Open **./src/extensions/helloWorld/HelloWorldApplicationCustomizer.manifest.json**.
|
66 | 66 |
|
67 | 67 | This file defines your extension type and a unique identifier for your extension. You’ll need this ID later when you debug and deploy your extension to SharePoint.
|
| 68 | + |
| 69 | + ```json |
| 70 | + { |
| 71 | + "$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-extension-manifest.schema.json", |
| 72 | + |
| 73 | + "id": "05966ad1-55c7-47f6-9ff5-4fee8bff838a", |
| 74 | + "alias": "HelloWorldApplicationCustomizer", |
| 75 | + "componentType": "Extension", |
| 76 | + "extensionType": "ApplicationCustomizer", |
| 77 | + |
| 78 | + // The "*" signifies that the version should be taken from the package.json |
| 79 | + "version": "*", |
| 80 | + "manifestVersion": 2, |
| 81 | + // If true, the component can only be installed on sites where Custom Script is allowed. |
| 82 | + // Components that allow authors to embed arbitrary script code should set this to true. |
| 83 | + // https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f |
| 84 | + "requiresCustomScript": false |
| 85 | + } |
| 86 | + ``` |
68 | 87 |
|
69 | 88 | ## Code your Application Customizer
|
70 | 89 |
|
71 | 90 | Open the **./src/extensions/helloWorld/HelloWorldApplicationCustomizer.ts** file.
|
72 | 91 |
|
73 | 92 | Notice that base class for the Application Customizer is imported from the **\@microsoft/sp-application-base** package, which contains SharePoint framework code required by the Application Customizer.
|
74 | 93 |
|
| 94 | +```typescript |
| 95 | +import { override } from '@microsoft/decorators'; |
| 96 | +import { Log } from '@microsoft/sp-core-library'; |
| 97 | +import { |
| 98 | + BaseApplicationCustomizer |
| 99 | +} from '@microsoft/sp-application-base'; |
| 100 | +import { Dialog } from '@microsoft/sp-dialog'; |
| 101 | + ``` |
| 102 | + |
75 | 103 | The logic for your Application Customizer is contained in the `onInit()` method, which is called when the client-side extension is first activated on the page. This event occurs after `this.context` and `this.properties` are assigned. As with web parts, `onInit()` returns a promise that you can use to do asynchronous operations.
|
76 | 104 |
|
77 | 105 | > [!NOTE]
|
78 | 106 | > The class constructor is called at an early stage, when `this.context` and `this.properties` are undefined. Custom initiation logic is not supported here.
|
79 | 107 |
|
80 | 108 | The following are the contents of `onInit()` in the default solution. This default solution writes a log to the Dev Dashboard, and then displays a simple JavaScript alert when the page renders.
|
81 | 109 |
|
| 110 | +```typescript |
| 111 | + @override |
| 112 | + public onInit(): Promise<void> { |
| 113 | + Log.info(LOG_SOURCE, `Initialized ${strings.Title}`); |
| 114 | + |
| 115 | + let message: string = this.properties.testMessage; |
| 116 | + if (!message) { |
| 117 | + message = '(No properties were provided.)'; |
| 118 | + } |
| 119 | + |
| 120 | + Dialog.alert(`Hello from ${strings.Title}:\n\n${message}`); |
| 121 | + |
| 122 | + return Promise.resolve(); |
| 123 | + } |
| 124 | +``` |
| 125 | + |
82 | 126 | > [!NOTE]
|
83 | 127 | > **SharePoint Framework Dev Dashboard** is additional UI dashboard, which can be started with <kbd>CTRL</kbd>+<kbd>F12</kbd> on Windows. This is developer oriented logging information, which you can take advantage as developer.
|
84 | 128 |
|
|
0 commit comments