You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spfx/extensions/get-started/using-page-placeholder-with-extensions.md
+34-32Lines changed: 34 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,21 @@
1
1
# Using page placeholders from Application Customizer (Hello World part 2)
2
2
3
-
>**Note:** The SharePoint Framework Extensions are currently in preview and is subject to change. SharePoint Framework Extensions are not currently supported for use in production environments.
3
+
>**Note:** The SharePoint Framework Extensions are currently in preview and are subject to change. SharePoint Framework Extensions are not currently supported for use in production environments.
4
4
5
-
Application Customizers also support you to access well known locations in the page, which you can modify based on your business and functional requirements. Typical scenarios would be for example dynamic header and footer experiences, which would be visible cross all the pages in SharePoint Online.
5
+
Application Customizers also provide access to well known locations in the page, which you can modify based on your business and functional requirements. Typical scenarios would be dynamic header and footer experiences, which would be visible across all the pages in SharePoint Online.
6
6
7
-
This is similar model as using UserCustomAction collection in Site or Web object to associate custom JavaScript, which would be used to modify page experience. Key different or advantage with SPFx extensions is that you will have guaranteed elements in the page also in case of any html dom structure modifications with future changes in SharePoint Online.
7
+
This model is similar to using a UserCustomAction collection in a Site or Web object to associate custom JavaScriptto modify the page experience. The key difference or advantage with SPFx extensions is that you have guaranteed elements on the page regardless of any HTML/DOM structure modifications in future changes to SharePoint Online.
8
8
9
-
In this article, we'll continue extending hello world extension built in the previous article [Build your first SharePoint Framework Extension (Hello World part 1)](./build-a-hello-world-extension.md) to take advantage of the page placeholders.
9
+
In this article, we'll continue extending the hello world extension built in the previous article [Build your first SharePoint Framework Extension (Hello World part 1)](./build-a-hello-world-extension.md) to take advantage of the page placeholders.
10
10
11
-
## Get access to page placeholders
11
+
## Getting access to page placeholders
12
12
13
-
Application Customizer extensions are supported with `Site`, `Web` and `List` scopes. You can control the scope by deciding where or how the Application Customizer will be registered in our SharePoint tenant. When Application Customizer exists in the scope and is being rendered, you use following method in the code to get access on placeholder. Once you have received the placeholder object, you have full control on deciding what will be presented for end users.
13
+
Application Customizer extensions are supported with `Site`, `Web` and `List` scopes. You can control the scope by deciding where or how the Application Customizer will be registered in your SharePoint tenant. When the Application Customizer exists in the scope and is being rendered, you can use the following method to get access to the placeholder. Once you have received the placeholder object, you have full control over what will be presented to the end user.
14
14
15
-
Notice that we are requesting well-known placeholder by using their well known identifier. In this casecode is accessing header section of the page using `PageHeader` identifier.
15
+
Notice that we are requesting a well-known placeholder by using the corresponding well-known identifier. In this case, the code is accessing the header section of the page using the`PageHeader` identifier.
@@ -25,11 +25,11 @@ Notice that we are requesting well-known placeholder by using their well known i
25
25
}
26
26
```
27
27
28
-
In following steps, we'll modify previously created hello word Application Customizer to access placeholders and to modify their content by adding custom html elements to them.
28
+
In the following steps, we'll modify the previously created hello word Application Customizer to access placeholders and modify their content by adding custom html elements to them.
29
29
30
-
Switch to Visual Studio code (or your preferred IDE) and open **src\extesions\helloWorld\HelloWorldApplicationCustomizer.ts.**
30
+
Switch to Visual Studio Code (or your preferred IDE) and open **src\extensions\helloWorld\HelloWorldApplicationCustomizer.ts.**
31
31
32
-
Add the `Placeholder` to the import section from `@microsoft/sp-application-base` by updating import as follows:
32
+
Add the `Placeholder` to the import from `@microsoft/sp-application-base` by updating the import statement as follows:
33
33
34
34
```ts
35
35
import {
@@ -38,19 +38,21 @@ import {
38
38
} from'@microsoft/sp-application-base';
39
39
```
40
40
41
-
Add also following imports under the `strings` import on top of the file:
42
-
* We will create style definitions for the output in following steps
41
+
Also add the following import statements after the `strings` import at the top of the file:
42
+
43
+
* We will create style definitions for the output in the following steps
43
44
*`escape` is used to escape Application Customizer properties
Create a new file call**AppCustomizer.module.scss** under **src\extesions\helloWorld** folder.
51
+
Create a new file named**AppCustomizer.module.scss** under the **src\extensions\helloWorld** folder.
51
52
52
53
Update **AppCustomizer.module.scss** as follows:
53
-
* These are the styles used to output html for the header and footer placeholders.
54
+
55
+
* These are the styles that will be used within the outputed html for the header and footer placeholders.
54
56
55
57
```css
56
58
.app {
@@ -77,9 +79,9 @@ Update **AppCustomizer.module.scss** as follows:
77
79
78
80
```
79
81
80
-
Move back to **HelloWorldApplicationCustomizer.ts** and update **IHelloWorldApplicationCustomizerProperties** interface to have specific properties for Header and Footer as follows.
82
+
Move back to **HelloWorldApplicationCustomizer.ts** and update the **IHelloWorldApplicationCustomizerProperties** interface to have specific properties for Header and Footer as follows.
81
83
82
-
* If your command set uses the ClientSideComponentProperties JSON input, it will be deserialized into the BaseExtension.properties object. You can define an interface to describe it.
84
+
* If your command set uses the ClientSideComponentProperties JSON input, it will be deserialized into the `BaseExtension.properties` object. You can define an interface to describe it.
Add following private variable inside of the **HelloWorldApplicationCustomizer** class. In this scenario, these could be also local variables in a`onRender` method, but if you'd want to share that to other objects, you'd define that as private variables.
93
+
Add the following private variables inside of the **HelloWorldApplicationCustomizer** class. In this scenario, these could just be local variables in an`onRender` method, but if you want to share them with other objects you define them as private variables.
92
94
93
95
```ts
94
96
exportdefaultclassHelloWorldApplicationCustomizer
@@ -103,8 +105,8 @@ Update the `onRender` method with the following code:
103
105
104
106
* We use `this.context.placeholders.tryAttach` to get access on the placeholder
105
107
* Extension code should not assume that the expected placeholder is available
106
-
* Code expects a custom property called `Header`and `Footer`. If properties exist, they will be rendered inside of the placeholder.
107
-
* Notice that code path for both header and footer is almost identical in the below method, only different is the used variables and style definitions.
108
+
* The code expects custom properties called `Header`and `Footer`. If the properties exist, they will be rendered inside of the placeholders.
109
+
* Notice that the code path for both the header and the footer is almost identical in the below method. The only differences are the variables used and the style definitions.
108
110
109
111
```ts
110
112
@override
@@ -114,7 +116,7 @@ Update the `onRender` method with the following code:
@@ -155,7 +157,7 @@ Update the `onRender` method with the following code:
155
157
156
158
// The extension should not assume that the expected placeholder is available.
157
159
if (!this._footerPlaceholder) {
158
-
console.error('The expected placeholder was not found.');
160
+
console.error('The expected placeholder (PageFooter) was not found.');
159
161
return;
160
162
}
161
163
@@ -179,7 +181,7 @@ Update the `onRender` method with the following code:
179
181
180
182
```
181
183
182
-
Add following method under the `onRender` method. In this case we simply output a console message, when extension is removed from the page.
184
+
Add the following method after the `onRender` method. In this case, we simply output a console message, when the extension is removed from the page.
183
185
184
186
```ts
185
187
private _onDispose():void {
@@ -188,11 +190,11 @@ Add following method under the `onRender` method. In this case we simply output
188
190
189
191
```
190
192
191
-
Code is now ready to be tested in SharePoint Online.
193
+
The code is now ready to be tested in SharePoint Online.
192
194
193
195
Switch to the console window that is running `gulpserve` and check if there are any errors. If there are errors, gulp reports them in the console and you will need to fix them before proceeding.
194
196
195
-
If you don't have solution running currently, execute following command and ensure that you don't have any errors.
197
+
If you don't have the solution running currently, execute the following command and ensure you don't have any errors.
196
198
197
199
```
198
200
gulpserve--nobrowser
@@ -203,24 +205,24 @@ Navigate to an out of the box modern list in SharePoint Online. This can be a li
203
205
To test your extension, append the following query string parameters to the URL:
204
206
205
207
* Notice that the GUID used in this query parameter has to match on the ID attribute of your Application Customizer available from **HelloWorldApplicationCustomizer.manifest.json**.
206
-
* We also use Header and Footer JSON properties to provide parameters or configurations to the Application Customizer. In this case we simply output these values, but you could adjust the behavior based on the properties in actual production usage.
208
+
* We also use Header and Footer JSON properties to provide parameters or configurations to the Application Customizer. In this case, we simply output these values, but you could adjust the behavior based on the properties in actual production usage.
207
209
208
210
```
209
211
?loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js&customActions={"5fc73e12-8085-4a4b-8743-f6d02ffe1240":{"___location":"ClientSideExtension.ApplicationCustomizer","properties":{"Header":"Header area of the page","Footer":"Footer area in the page"}}}
210
212
```
211
-
Full URL to request would be something like following:
213
+
The full URL to request would be something like the following:
212
214
213
215
```
214
216
contoso.sharepoint.com/Lists/Contoso/AllItems.aspx?loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js&customActions={"5fc73e12-8085-4a4b-8743-f6d02ffe1240":{"___location":"ClientSideExtension.ApplicationCustomizer","properties":{"Header":"Header area of the page","Footer":"Footer area in the page"}}}
215
217
```
216
218
217
219

218
220
219
-
Click "**Load debug scripts**" button to continue loading scripts from your local host.
221
+
Click the "**Load debug scripts**" button to continue loading scripts from your local host.
220
222
221
-
You should now see the alert message in your page.
223
+
You should now see the custom header and footer content in your page.
222
224
223
225

224
226
225
227
## Next steps
226
-
Congratulations on building your own custom header and footer from Application Customizer. You can continue building out your Hello World Extension in the next topic [Deploy your extension to site collection (Hello world part 3)](./serving-your-extension-from-sharepoint.md). You will learn how to deploy and preview the Hello World extension in SharePoint site collection without using **Debug** query parameters.
228
+
Congratulations on building your own custom header and footer using the Application Customizer! You can continue building out your Hello World Extension in the next topic [Deploy your extension to site collection (Hello world part 3)](./serving-your-extension-from-sharepoint.md). You will learn how to deploy and preview the Hello World extension in a SharePoint site collection without using **Debug** query parameters.
0 commit comments