|
1 | 1 | ---
|
2 | 2 | title: Understanding and configuring the publishing page transformation model
|
3 | 3 | description: Provides detailed guidance on how to configure and use the publishing page transformation model
|
4 |
| -ms.date: 09/04/2019 |
| 4 | +ms.date: 09/11/2019 |
5 | 5 | ms.prod: sharepoint
|
6 | 6 | localization_priority: Normal
|
7 | 7 | ---
|
@@ -382,6 +382,57 @@ Sometimes a page layout contains text snippets, which since they're not content
|
382 | 382 | > [!Note]
|
383 | 383 | > The HTML provided in the StaticString function must be XML encoded and must be formatted like the source page HTML as this HTML will still be converted to HTML which is compliant with the modern text editor
|
384 | 384 |
|
| 385 | +### I want to add an extra web part on the created page |
| 386 | + |
| 387 | +When you transform you classic publishing page to a modern page you sometimes want to add an **additional** modern web part on the created page, without that there's a classic version of that web part on the classic publishing page. This can be done by adjusting your webpartmapping.xml and page layout mapping files as shown below. |
| 388 | + |
| 389 | +First define your custom web part in your **webpartmapping.xml** file by **adding** it the `WebParts` element in the file like shown in this [standard SPFX Hello World web part](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part): |
| 390 | + |
| 391 | +```XML |
| 392 | +<WebParts> |
| 393 | + ... |
| 394 | + <!-- Custom Hello world web part--> |
| 395 | + <WebPart Type="SharePointPnP.Demo.HelloWorld" CrossSiteTransformationSupported="true"> |
| 396 | + <Properties> |
| 397 | + <Property Name="HelloWorld" Type="string" /> |
| 398 | + </Properties> |
| 399 | + <Mappings> |
| 400 | + <Mapping Default="true" Name="default"> |
| 401 | + <ClientSideWebPart Type="Custom" ControlId="157b22d0-8006-4ec7-bf4b-ed62383fea76" Order="10" JsonControlData="{"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}},"dataVersion":"1.0","properties":{"description":"{HelloWorld}","test":"Multi-line text field","test1":true,"test2":"2","test3":true}}"/> |
| 402 | + </Mapping> |
| 403 | + </Mappings> |
| 404 | +</WebPart> |
| 405 | + ... |
| 406 | +</WebParts> |
| 407 | +``` |
| 408 | + |
| 409 | +If you're not how to correctly define your custom web part in above **ClientSideWebPart** element then follow these steps: |
| 410 | + |
| 411 | +- Navigate to the SharePoint Framework Workbench in your site (e.g. https://contoso.sharepoint.com/sites/myportalsite/_layouts/workbench.aspx) |
| 412 | +- Add your custom web part to the workbench and configure it when needed |
| 413 | +- Click on the "Web part data" button in the toolbar and then on the "Modern Pages" button |
| 414 | +- Copy the **WebPartData** json structure and use it to complete next steps: |
| 415 | + - The **ControlId** guid value is the value of the **id** json property |
| 416 | + - Delete the following json properties from the copied snippet: id, instanceIf, title and description. At this point you have the following left: `{"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}},"dataVersion":"1.0","properties":{"description":"HelloWorld from Bert","test":"Multi-line text field","test1":true,"test2":"2","test3":true}}` |
| 417 | + - XML encode this string, this will give you this: `{"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}},"dataVersion":"1.0","properties":{"description":"HelloWorld from Bert","test":"Multi-line text field","test1":true,"test2":"2","test3":true}}` |
| 418 | + - If needed insert web part parameters in this string (e.g. {HelloWorld} in above sample): `{"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{},"links":{}},"dataVersion":"1.0","properties":{"description":"{HelloWorld}","test":"Multi-line text field","test1":true,"test2":"2","test3":true}}` |
| 419 | + - Paste the resulting string in the **JsonControlData** property |
| 420 | + |
| 421 | +Once that's in place you need to update your page layout mapping by adding a field in the **WebParts** section that will be transformed to this custom web part: |
| 422 | + |
| 423 | +```XML |
| 424 | +<WebParts> |
| 425 | + ... |
| 426 | + <!-- Add an extra web part on the page --> |
| 427 | + <Field Name="ID" TargetWebPart="SharePointPnP.Demo.HelloWorld" Row="4" Column="1" Order="1"> |
| 428 | + <Property Name="HelloWorld" Type="string" Functions="StaticString('PnP Rocks!')"/> |
| 429 | + </Field> |
| 430 | + ... |
| 431 | +</WebParts> |
| 432 | +``` |
| 433 | + |
| 434 | +Ensure that specify the custom **webpartmapping.xml** file as part of your transformation (`-WebPartMappingFile` PowerShell cmdlet parameter, `PublishingPageTransformator` constructor when using .Net). |
| 435 | + |
385 | 436 | ### Can I control the page preview image (as of the May 2019 release)
|
386 | 437 |
|
387 | 438 | When a page has a page header image that image will also be used as a page preview image. If you however want to control the page preview image then you can populate the `BannerImageUrl` field using either the `ToPreviewImageUrl` function or by specifying a hard coded value as shown in below samples.
|
|
0 commit comments