SharePoint custom header, SPFx Extension - Add Custom Header and Footer using SharePoint Framework Extension

SharePoint Framework Header Footer: Add Custom Header and Footer Using SPFx

No comments

Loading

In this SharePoint Framework header footer article, we will learn about how to add a custom header and footer message to the SharePoint Online site page using the SharePoint Framework (SPFx) extension application customizer.

Key-Highlights: SharePoint Framework header footer

  • Using SPFx add a custom header and footer message on the SharePoint Online Page
  • Create an extension project step-by-step process โ€“ scaffolding process
  • How to modify the alias name in the manifest.json file?
  • Steps to implement Application Customizer โ€“ Header and Footer
  • HeaderAndFooterAppExtensionApplicationCustomizer.ts file content
  • Implementation of the OnInit() method
  • Implementation of the _renderPlaceHolders() method
  • Apply custom CSS for Header and Footer in SPFx
  • Demo โ€“ verify the custom header and footer application extension from SharePoint Online page
  • Download Source Code
  • When should we use the extension type solution in the SPFx Framework?
  • Summary

Create an extension project step-by-step process โ€“ scaffolding process (SharePoint Framework header footer)

  1. Create a new project directory (folder) in your specified location using the below command:

C:\Temp\SPFx\Application Extension>md HeaderAndFooter_App_Extension

2. Go to the project directory using the below command

cd HeaderAndFooter_App_Extension
SharePoint Framework header footer, create a project directory for the SPFx Application extension project - Header and Footer
Create a project directory for the SPFx Application extension project โ€“ Header and Footer

3. Run the yo @microsoft/sharepoint command to generate the extension project.

C:\Temp\SPFx\Application Extension>HeaderAndFooter_App_Extension>yo @microsoft/sharepoint

4. Pass the input parameters as prompts:

Let's create a new SharePoint solution.
? What is your solution name? header-and-footer-app-extension
? Which baseline packages do you want to target for your component(s)? SharePoint Online only (latest)
? Where do you want to place the files? Use the current folder
Found npm version 6.14.7
? Do you want to allow the tenant admin the choice of being able to deploy the solution to all sites immediately without
running any feature deployment or adding apps in sites? No
? Will the components in the solution require permissions to access web APIs that are unique and not shared with other c
omponents in the tenant? No
? Which type of client-side component to create? Extension
? Which type of client-side extension to create? Application Customizer
Add new Application Customizer to solution header-and-footer-app-extension.
? What is your Application Customizer name? Header-and-footer-app-extension
? What is your Application Customizer description? (Header-and-footer-app-extension description)
SPFx Application extension project - yo microsoft-sharepoint - Header and Footer
SPFx Application extension project โ€“ yo microsoft-sharepoint โ€“ Header and Footer

After some time, we can see that the SPFx application extension project โ€“ scaffolding is completed.

SharePoint Framework header footer, SPFx Application extension project - scaffolding completed - Header and Footer
SPFx Application extension project โ€“ scaffolding completed โ€“ Header and Footer

Note:

While passing the name of the extension, try to keep length within 40 characters โ€“ in the manifest JSON file an alias name is registered. Nevertheless, if you face any issues during running the gulp serve โ€“nobrowser command, we can resolve this by updating the alias entry afterward.

Below is the reference on how to modify the alias name in the manifest.json file?

SharePoint Framework header footer, alias name in manifest.json file - SPFx extension application customizer
Alias name in manifest.json file โ€“ SPFx extension application customizer

5. Open the project in the visual studio editor

Run the โ€œCode .โ€ command to open the project in the visual studio editor.

C:\Temp\SPFx\Application Extension\HeaderAndFooter_App_Extension>code .

6. Analysis of code file structure (SPFx footer bottom of page)

Open the HeaderAndFooterAppExtensionApplicationCustomizer.manifest.json file

Go to the below path to open the HeaderAndFooterAppExtensionApplicationCustomizer.manifest.json file.

./src/extensions/headerAndFooterAppExtension/HeaderAndFooterAppExtensionApplicationCustomizer.manifest.json

This file defines your extension type and a unique identifier for your extension. We will need this ID later when we debug and deploy the extension to SharePoint Online.

File Content:

{

ย ย "$schema":ย "https://developer.microsoft.com/json-schemas/spfx/client-side-extension-manifest.schema.json",

ย ย "id":ย "c20e744e-6f99-47cf-bfde-3a2240a98f8f",

ย ย "alias":ย "HeaderAndFooterAppExtensionApplicationCu",

ย ย "componentType":ย "Extension",

ย ย "extensionType":ย "ApplicationCustomizer",

ย ย //ย Theย "*"ย signifiesย thatย theย versionย shouldย beย takenย fromย theย package.json

ย ย "version":ย "*",

ย ย "manifestVersion":ย 2,

ย ย //ย Ifย true,ย theย componentย canย onlyย beย installedย onย sitesย whereย Customย Scriptย isย allowed.

ย ย //ย Componentsย thatย allowย authorsย toย embedย arbitraryย scriptย codeย shouldย setย thisย toย true.

ย ย //ย https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f

ย ย "requiresCustomScript":ย false

}
SharePoint Framework header footer, Manifest.json file in the SPFx application customizer project - Header and Footer
Manifest.json file in the SPFx application customizer project โ€“ Header and Footer

Notes:

  • The โ€œ*โ€ signifies that the version should be taken from the package.json.
  • If true, the component can only be installed on sites where Custom Script is allowed.

6. Steps to implement Application Customizer โ€“ Header and Footer (SharePoint Framework header footer)

6.1 Open the HeaderAndFooterAppExtensionApplicationCustomizer.ts file

Go to the below path to open the HeaderAndFooterAppExtensionApplicationCustomizer.ts file.

./src/extensions/headerAndFooterAppExtension/HeaderAndFooterAppExtensionApplicationCustomizer.ts

HeaderAndFooterAppExtensionApplicationCustomizer.ts file content:

importย {ย overrideย }ย fromย '@microsoft/decorators';

importย {ย Logย }ย fromย '@microsoft/sp-core-library';

importย {

ย ย BaseApplicationCustomizer

}ย fromย '@microsoft/sp-application-base';

importย {ย Dialogย }ย fromย '@microsoft/sp-dialog';

importย *ย asย stringsย fromย 'HeaderAndFooterAppExtensionApplicationCustomizerStrings';

constย LOG_SOURCE:ย stringย =ย 'HeaderAndFooterAppExtensionApplicationCustomizer';

/**

ย *ย 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.

ย */

exportย interfaceย IHeaderAndFooterAppExtensionApplicationCustomizerPropertiesย {

ย ย //ย Thisย isย anย example;ย replaceย withย yourย ownย property

ย ย testMessage:ย string;

}

/**ย Aย Customย Actionย whichย canย beย runย duringย executionย ofย aย Clientย Sideย Applicationย */

exportย defaultย classย HeaderAndFooterAppExtensionApplicationCustomizer

ย ย extendsย BaseApplicationCustomizer<IHeaderAndFooterAppExtensionApplicationCustomizerProperties>ย {

ย ย @override

ย ย publicย onInit():ย Promise<void>ย {

ย ย ย ย Log.info(LOG_SOURCE,ย `Initializedย ${strings.Title}`);

ย ย ย ย letย message:ย stringย =ย this.properties.testMessage;

ย ย ย ย ifย (!message)ย {

ย ย ย ย ย ย messageย =ย '(Noย propertiesย wereย provided.)';

ย ย ย ย }

ย ย ย ย Dialog.alert(`Helloย fromย ${strings.Title}:\n\n${message}`);

ย ย ย ย returnย Promise.resolve();

ย ย }

}
HeaderAndFooterAppExtensionApplicationCustomizer.ts file in the SPFx application customizer project
HeaderAndFooterAppExtensionApplicationCustomizer.ts file in the SPFx application customizer project

The above-mentioned code is generated thru the out of the SPFx scaffolding process.

Now, letโ€™s customize the above code to implement the header and footer functionality in SharePoint Online site.

In order to get access to placeholders on the page, we need to use the below imports:

import { 
BaseApplicationCustomizer, 
PlaceholderContent, 
PlaceholderName 
} from '@microsoft/sp-application-base';

ย 

Then, now letโ€™s add our custom property โ€œTopโ€ and โ€œBottomโ€ in the IHeaderAndFooterAppExtensionApplicationCustomizerProperties interface.

exportย interfaceย IHeaderAndFooterAppExtensionApplicationCustomizerProperties

ย {

ย ย //ย Thisย isย anย example;ย replaceย withย yourย ownย property

ย ย //testMessage:ย string;

ย ย Top:ย string;ย ย 

ย ย Bottom:ย string;

}

Note:
  • For our convenience, the SPFx project scaffolding will generate this interface with the โ€œtestMessageโ€ which we have commented on now as we have added two real properties (Top and Bottom).

Now, letโ€™s have a look at the HeaderAndFooterAppExtensionApplicationCustomizer.ts file after adding the new codes.

SharePoint Framework header footer, headerAndFooterCustom property in AppExtensionApplicationCustomizer.ts file in the SPFx application customizer project
HeaderAndFooterCustom property in AppExtensionApplicationCustomizer.ts file in the SPFx application customizer project.

6.2 Implementation of the OnInit() method

Below is the code for OnInit() method which gets executed when the page starts loading, then call the render method displaying the header and footer.

privateย _topPlaceholderHeader:ย PlaceholderContentย |ย undefined;

private _bottomPlaceholderFooter: PlaceholderContent | undefined;

ย ย @override

ย ย publicย onInit():ย Promise<void>ย 

ย ย {

ย ย ย ย Log.info(LOG_SOURCE,ย `Initializedย ${strings.Title}`);

ย ย ย ย this.context.placeholderProvider.changedEvent.add(this,ย this._renderPlaceHoldersHeaderandFooter);

ย ย ย ย //Addedย theย belowย lineย codeย toย handleย theย possibleย changesย onย theย existenceย ofย placeholders.ย ย 

ย ย ย ย this.context.placeholderProvider.changedEvent.add(this,ย this._renderPlaceHoldersHeaderandFooter);ย ย 
 ย ย ย ย 

ย ย ย ย //Theย belowย codeย isย usedย toย callย renderย methodย forย generatingย theย HTMLย elements.ย ย 

ย ย ย ย this._renderPlaceHoldersHeaderandFooter();ย 


ย ย ย ย returnย Promise.resolve();

ย ย }
OnInit method in SPFx Extension Application Customizer project
OnInit method in SPFx Extension Application Customizer project

6.2 Implementation of the _renderPlaceHolders() method (SPFx footer bottom of page

If we little scroll down the HeaderAndFooterAppExtensionApplicationCustomizer.ts file we can see that _renderPlaceHoldersHeaderandFooter() has been implemented which is primarily responsible for page rendering for the header and footer functionality.

privateย _renderPlaceHoldersHeaderandFooter():ย void

ย ย ย {ย ย 

ย ย ย ย console.log('HeaderAndFooterAppExtensionApplicationCustomizer._renderPlaceHoldersHeaderandFooter()');ย ย 

ย ย ย ย console.log('Availableย placeholdersย areย asย below:ย ',ย ย 

ย ย ย ย this.context.placeholderProvider.placeholderNames.map(nameย =>ย PlaceholderName[name]).join(',ย '));ย ย 

ย ย ย ย ย ย 

ย ย ย ย //Handlingย theย topย placeholderย -ย headerย section

ย ย ย ย ifย (!this._topPlaceholderHeader)

ย ย ย ย ย {ย ย 

ย ย ย ย ย ย this._topPlaceholderHeaderย =ย ย 

ย ย ย ย ย ย ย ย this.context.placeholderProvider.tryCreateContent(ย ย 

ย ย ย ย ย ย ย ย ย ย PlaceholderName.Top,ย ย 

ย ย ย ย ย ย ย ย ย ย {ย 

ย ย ย ย ย ย ย ย ย ย ย ย onDispose:ย this._onDispose

ย ย ย ย ย ย ย ย ย ย });ย ย 

ย ย ย ย ย ย 

ย ย ย ย ย ย //Theย extensionย shouldย notย assumeย thatย theย expectedย placeholderย isย available.ย ย 

ย ย ย ย ย ย ifย (!this._topPlaceholderHeader)

ย ย ย ย ย ย ย {ย ย 

ย ย ย ย ย ย ย ย console.error('Theย expectedย placeholderย (topย heder)ย wasย notย found.');ย ย 

ย ย ย ย ย ย ย ย return;ย ย 

ย ย ย ย ย ย }ย ย 

ย ย ย ย ย ย 

ย ย ย ย ย ย ifย (this.properties)ย {ย ย 

ย ย ย ย ย ย ย ย letย topString:ย stringย =ย this.properties.Top;ย ย 

ย ย ย ย ย ย ย ย ifย (!topString)ย {ย ย 

ย ย ย ย ย ย ย ย ย ย topStringย =ย '(Theย topย headerย propertyย wasย notย defined.)';ย ย 

ย ย ย ย ย ย ย ย }ย ย 

ย ย ย ย ย ย 

ย ย ย ย ย ย ย ย ifย (this._topPlaceholderHeader.domElement)

ย ย ย ย ย ย ย ย ย {ย ย 

ย ย ย ย ย ย ย ย ย ย this._topPlaceholderHeader.domElement.innerHTMLย =ย `ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย <divย class="${styles.appCustomHeaderFooter}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย <divย class="ms-bgColor-themeDarkย ms-fontColor-whiteย ${styles.top}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย <iย class="ms-Iconย ms-Icon--Info"ย aria-hidden="true"></i>ย ${escape(topString)}ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย </div>ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย </div>`;ย ย 

ย ย ย ย ย ย ย ย }ย ย 

ย ย ย ย ย ย }ย ย 

ย ย ย ย }ย ย 

ย ย ย ย ย ย 

ย ย ย ย //Handlingย theย bottomย placeholderย -ย Footerย section

ย ย ย ย ifย (!this._bottomPlaceholderFooter)

ย ย ย ย ย {ย ย 

ย ย ย ย ย ย this._bottomPlaceholderFooterย =ย ย 

ย ย ย ย ย ย ย ย this.context.placeholderProvider.tryCreateContent(ย ย 

ย ย ย ย ย ย ย ย ย ย PlaceholderName.Bottom,ย ย 

ย ย ย ย ย ย ย ย ย ย {ย onDispose:ย this._onDisposeย });ย ย 

ย ย ย ย ย ย 

ย ย ย ย ย ย //ย Theย extensionย shouldย notย assumeย thatย theย expectedย placeholderย isย available.ย ย 

ย ย ย ย ย ย ifย (!this._bottomPlaceholderFooter)ย {ย ย 

ย ย ย ย ย ย ย ย console.error('Theย expectedย placeholderย (Bottomย Footer)ย wasย notย found.');ย ย 

ย ย ย ย ย ย ย ย return;ย ย 

ย ย ย ย ย ย }ย ย 

ย ย ย ย ย ย 

ย ย ย ย ย ย ifย (this.properties)ย {ย ย 

ย ย ย ย ย ย ย ย letย bottomString:ย stringย =ย this.properties.Bottom;ย ย 

ย ย ย ย ย ย ย ย ifย (!bottomString)ย {ย ย 

ย ย ย ย ย ย ย ย ย ย bottomStringย =ย '(Theย bottomย footerย propertyย wasย notย defined.)';ย ย 

ย ย ย ย ย ย ย ย }ย ย 

ย ย ย ย ย ย 

ย ย ย ย ย ย ย ย ifย (this._bottomPlaceholderFooter.domElement)

ย ย ย ย ย ย ย ย {ย ย 

ย ย ย ย ย ย ย ย ย ย this._bottomPlaceholderFooter.domElement.innerHTMLย =ย `ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย <divย class="${styles.appCustomHeaderFooter}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย <divย class="ms-bgColor-themeDarkย ms-fontColor-whiteย ${styles.bottom}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย <iย class="ms-Iconย ms-Icon--Info"ย aria-hidden="true"></i>ย ${escape(bottomString)}ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย </div>ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย </div>`;ย ย 

ย ย ย ย ย ย ย ย }ย ย 

ย ย ย ย ย ย }ย ย 

ย ย ย ย }ย ย 

ย }
SharePoint Framework header footer, render Place Holder method in SPFx extension application customizer project
Render Place Holder method in SPFx extension application customizer project

_onDispose() method is used the _renderPlaceHoldersHeaderandFooter() โ€“ here is the implementation of the _onDispose() method.

privateย _onDispose():ย voidย 

ย {

ย ย ย console.log('[HeaderAndFooterAppExtensionApplicationCustomizer._onDispose]ย Disposedย fromย theย topย headerย andย bottomย footerย placeholders.');

ย }
_onDispose method is SPFx framework extension application customizer project
_onDispose method is SPFx framework extension application customizer project

ย 

Notes:

  • In the above _renderPlaceHoldersHeaderandFooter() method styles.top and styles.bottom were used, in the subsequent section we will learn how these two CSS classes have been referred here.

6.3 Apply custom CSS for Header and Footer (SharePoint Framework header footer)

Header CSS:

<divย class="${styles.appCustomHeaderFooter}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย <divย class="ms-bgColor-themeDarkย ms-fontColor-whiteย ${styles.top}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย <iย class="ms-Iconย ms-Icon--Info"ย aria-hidden="true"></i>ย ${escape(topString)}ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย </div>ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย </div>`;

Footer CSS:

<divย class="${styles.appCustomHeaderFooter}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย <divย class="ms-bgColor-themeDarkย ms-fontColor-whiteย ${styles.bottom}">ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย <iย class="ms-Iconย ms-Icon--Info"ย aria-hidden="true"></i>ย ${escape(bottomString)}ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย ย ย </div>ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย </div>`;ย 


In the above both the header and footer code, we can see those styles.appCustomHeaderFooter, styles.top, styles.bottom โ€“ now I will explain how these have been referred to here โ€“ or where these actually defined.

Step 1:

Below is the import CSS file:

importย stylesย fromย './HeaderAndFooterAppExtensionApplicationCustomizer.module.scss';

ย 

SharePoint Framework header footer, import custom CSS file in SPFx framework project
Import custom CSS file in SPFx framework project

Step 2:

Below are the .top and .bottom CSS class inside the .appCustomHeaderFooter parent CSS class which is located the custom CSS file โ€“ HeaderAndFooterAppExtensionApplicationCustomizer.module.scss file which is located at โ€œ\src\extensions\headerAndFooterAppExtension\โ€ folder.

.appCustomHeaderFooter

{

ย ย ย ย .topย 

ย ย ย ย {

ย ย ย ย ย color:Red;

ย ย ย ย ย line-height:2.5;

ย ย ย ย ย align-items:ย center;

ย ย ย ย ย ย height:60px;

ย ย ย ย ย ย justify-content:ย center;

ย ย ย ย ย ย text-align:center;ย ย ย ย ย ย 

ย ย ย ย ย ย font-weight:bold;

ย ย ย ย ย ย display:ย flex;ย ย ย ย ย 

ย ย ย ย ย ย font-size:30px

ย ย ย ย }

ย ย 

ย ย ย ย .bottom

ย ย ย ย ย {

ย ย ย ย ย ย color:Red;

ย ย ย ย ย ย height:40px;

ย ย ย ย ย ย align-items: center;

ย ย ย ย ย ย line-height:2.5;

ย ย ย ย ย ย font-weight:bold;

ย ย ย ย ย ย justify-content: center;

ย ย ย ย ย ย text-align:center;ย ย ย ย ย ย 

ย ย ย ย ย ย display: flex;ย ย ย ย ย ย 

ย ย ย ย ย ย font-size:30px

ย ย ย ย }

ย ย }

SharePoint Framework header footer, create custom CSS file in SPFx Application customizer project

Create a custom CSS file in SPFx Application customizer projectStep 3: Add another .ts file in the same path (โ€œ\src\extensions\headerAndFooterAppExtension\โ€) as HeaderAndFooterAppExtensionApplicationCustomizer.module.scss.ts file, and the below should be content of the file:

/*ย tslint:disableย */

require("./HeaderAndFooterAppExtensionApplicationCustomizer.module.css");

constย stylesย =ย {

ย ย appCustomHeaderFooter:ย 'appCustomHeaderFooter_30e7ead0',

ย ย top:ย 'top_30e7ead0',

ย ย bottom:ย 'bottom_30e7ead0'

};

exportย defaultย styles;

/*ย tslint:enableย */
SharePoint Framework header footer, application Custom Header Footer CSS in SPFx framework
Application Custom Header Footer CSS in SPFx framework

SharePoint Framework header footer demo โ€“ verify the custom header and footer application extension from SharePoint Online page

Open serve.json from the config folder.

Now, update the properties section to include Top and Bottom messages and Page URLs.

After updating, the file content should be as below:

{

ย ย "$schema":ย "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",

ย ย "port":ย 4321,

ย ย "https":ย true,

ย ย "serveConfigurations":ย {

ย ย ย ย "default":ย {

ย ย ย ย ย ย "pageUrl":ย "https://globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/SitePages/SPFxAppCustomizerTest.aspx",

ย ย ย ย ย ย "customActions":ย {

ย ย ย ย ย ย ย ย "c20e744e-6f99-47cf-bfde-3a2240a98f8f":ย {

ย ย ย ย ย ย ย ย ย ย "location":ย "ClientSideExtension.ApplicationCustomizer",

ย ย ย ย ย ย ย ย ย ย "properties":ย {ย ย ย ย ย ย ย ย ย ย ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย "Top":ย "Thisย customย headerย hasย beenย developedย byย SPFxย framework.",ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย "Bottom":ย "Thisย customย footerย hasย beenย developedย byย SPFxย framework."ย 

ย ย ย ย ย ย ย ย ย ย }

ย ย ย ย ย ย ย ย }

ย ย ย ย ย ย }

ย ย ย ย },

ย ย ย ย "headerAndFooterAppExtension":ย {

ย ย ย ย ย ย "pageUrl":ย "https://globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/SitePages/SPFxAppCustomizerTest.aspx",

ย ย ย ย ย ย "customActions":ย {

ย ย ย ย ย ย ย ย "c20e744e-6f99-47cf-bfde-3a2240a98f8f":ย {

ย ย ย ย ย ย ย ย ย ย "location":ย "ClientSideExtension.ApplicationCustomizer",

ย ย ย ย ย ย ย ย ย ย "properties":ย {

ย ย ย ย ย ย ย ย ย ย ย ย "Top":ย "Thisย customย headerย hasย beenย developedย byย SPFxย framework.",ย ย 

ย ย ย ย ย ย ย ย ย ย ย ย "Bottom":ย "Thisย customย footerย hasย beenย developedย byย SPFxย framework."ย 

ย ย ย ย ย ย ย ย ย ย }

ย ย ย ย ย ย ย ย }

ย ย ย ย ย ย }

ย ย ย ย }

ย ย }

}

SharePoint Framework header footer, serve.json file update for header and footer using SPFx extension application
Serve.json file update for header and footer using SPFx extension application
Note:
  • By default, the page URL would be:
"https://contoso.sharepoint.com/sites/mySite/SitePages/myPage.aspx", here we need a pass a custom page URL from our tenant.
Run the gup serve command.
Then we will get the warning message from the browser โ€“ โ€œAllow debug scripts?โ€
SharePoint Framework header footer, allow debug scripts - in SPFx framework extension - header and footer
Allow debug scripts?- in SPFx framework extension โ€“ header and footer

Click on the โ€œLoad debug scriptsโ€ button.

Then, we can see that the custom header and footer below mentioned messages have been displayed on the page:

  • This custom header has been developed by the SPFx framework.
  • This custom footer has been developed by the SPFx framework.
SharePoint Framework header footer, custom Header and Footer Demo in SPFx framework extension project
Custom Header and Footer Demo in SPFx framework extension project

SharePoint Framework header footer โ€“ when should we use the extension type solution in the SPFx Framework?

In the SPFx framework, we can develop three types of client-side solutions such as:

  1. WebPart
  2. Extension
  3. Library

As we can see the โ€œExtensionโ€ type is one among them. Each type of the above project type has its own need and scope when it comes to customizing the SharePoint solution. For example, using the web part we can display the SharePoint content in a specific area of the page, using the โ€œExtensionโ€ type we can customize the site level object such as site header, footer, navigation, etc., and using the โ€œLibraryโ€ type project we can customize the list/library, view, etc.

Download Source Code: SharePoint Framework header footer

The source code of the above SPFx header footer can be downloaded from the SharePoint Framework header footer GitHub.

Summary: SharePoint Framework header footer (What is Application Customizer in SPFx)

Thus, in this article, we have learned about how to add the custom header and footer message in the SharePoint Online page using the SPFx framework extension application customizer project, we can summarize the learning as below:

  • Using SPFx add a custom header and footer message in the SharePoint Online Page
  • How to create an extension project step-by-step process โ€“ the scaffolding process
  • How to modify the alias name in the manifest.json file?
  • Steps to implement Application Customizer โ€“ Header and Footer
  • What does the HeaderAndFooterAppExtensionApplicationCustomizer.ts file content?
  • How to implement the OnInit() method?
  • How to implement the _renderPlaceHolders() method?
  • How to apply custom CSS for Header and Footer using the SPFx framework extension application customizer?
  • Demo โ€“ verify the custom header and footer application extension from SharePoint Online page

See Also: SharePoint Framework header footer (SharePoint custom header)

You may also like the below SharePoint SPFx articles:

Hope you have enjoyed reading this article and helped you. If you would like to appreciate our efforts or if you have a better solution or a different opinion, please write to the below comment section and do share this with your friends and colleagues. ๐Ÿ™‚

ย 

About Post Author


Discover more from Global SharePoint

Subscribe to get the latest posts sent to your email.

Do you have a better solution or question on this topic? Please leave a comment