Skip to content

Commit cfad079

Browse files
Merge pull request SharePoint#6331 from panjkov/patch-5
Patch 5
2 parents 1ff3d96 + 25c8e2e commit cfad079

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed
17.3 KB
Loading
43.3 KB
Loading
20.1 KB
Loading

docs/spfx/extensions/get-started/build-a-hello-world-extension.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Build your first SharePoint Framework Extension (Hello World part 1)
33
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
55
ms.prod: sharepoint
66
localization_priority: Priority
77
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
6565
1. Open **./src/extensions/helloWorld/HelloWorldApplicationCustomizer.manifest.json**.
6666

6767
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+
```
6887

6988
## Code your Application Customizer
7089

7190
Open the **./src/extensions/helloWorld/HelloWorldApplicationCustomizer.ts** file.
7291

7392
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.
7493

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+
75103
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.
76104

77105
> [!NOTE]
78106
> The class constructor is called at an early stage, when `this.context` and `this.properties` are undefined. Custom initiation logic is not supported here.
79107
80108
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.
81109

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+
82126
> [!NOTE]
83127
> **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.
84128

0 commit comments

Comments
 (0)