Skip to content

Commit 25c8e2e

Browse files
authored
Update build-a-hello-world-extension.md
Replaced images with code snippets
1 parent 7f43944 commit 25c8e2e

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

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

Lines changed: 42 additions & 4 deletions
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: 10/1/2020
4+
ms.date: 10/2/2020
55
ms.prod: sharepoint
66
localization_priority: Priority
77
ms.custom: scenarios:getting-started
@@ -66,15 +66,39 @@ You can also follow the steps in this article by watching the video on the Share
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.
6868
69-
![Application Customizer manifest json content](../../../images/ext-app-vscode-manifest.png)
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+
```
7087

7188
## Code your Application Customizer
7289

7390
Open the **./src/extensions/helloWorld/HelloWorldApplicationCustomizer.ts** file.
7491

7592
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.
7693

77-
![Application Customizer imports and inheritance](../../../images/ext-app-vscode-app-base.png)
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+
```
78102

79103
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.
80104

@@ -83,7 +107,21 @@ The logic for your Application Customizer is contained in the `onInit()` method,
83107
84108
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.
85109

86-
![Default onInit method in the code](../../../images/ext-app-vscode-methods.png)
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+
```
87125

88126
> [!NOTE]
89127
> **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.

0 commit comments

Comments
 (0)