SharePoint Online: Customizing Modern Pages with SPFx Extensions

On this page

SPFx Extensions let you customize SharePoint beyond web parts. Add headers, footers, field customizers, or command sets. Here’s how to get started with these powerful customization options.

Types of Extensions

  • Application Customizer: Add elements to page header/footer
  • Field Customizer: Custom rendering for list columns
  • Command Set: Custom toolbar buttons and context menu items

Creating an Application Customizer

Bash3 lines
yo @microsoft/sharepoint
# Select "Extension"
# Select "Application Customizer"
TypeScript22 lines
import { BaseApplicationCustomizer, PlaceholderName } from '@microsoft/sp-application-base';

export default class HeaderCustomizer extends BaseApplicationCustomizer<{}> {

  public onInit(): Promise<void> {
    this.context.placeholderProvider.changedEvent.add(this, this.renderPlaceholders);
    return Promise.resolve();
  }

  private renderPlaceholders(): void {
    const topPlaceholder = this.context.placeholderProvider
      .tryCreateContent(PlaceholderName.Top);

    if (topPlaceholder) {
      topPlaceholder.domElement.innerHTML = `
        <div style="background: #0078d4; color: white; padding: 10px;">
          Welcome to our intranet!
        </div>
      `;
    }
  }
}

Field Customizer Example

TypeScript23 lines
import { BaseFieldCustomizer } from '@microsoft/sp-listview-extensibility';

export default class StatusFieldCustomizer extends BaseFieldCustomizer<{}> {
  
  public onRenderCell(event: IFieldCustomizerCellEventParameters): void {
    const status = event.fieldValue;
    
    const colors: Record<string, string> = {
      'Completed': '#4caf50',
      'In Progress': '#ff9800',
      'Not Started': '#f44336'
    };

    event.domElement.innerHTML = `
      <span style="
        background: ${colors[status] || '#gray'};
        color: white;
        padding: 4px 12px;
        border-radius: 12px;
      ">${status}</span>
    `;
  }
}

Deployment

Extensions deploy like web parts but require additional configuration:

JSON10 lines
{
  "$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-solution-manifest.schema.json",
  "solution": {
    "name": "header-extension",
    "id": "...",
    "version": "1.0.0.0",
    "includeClientSideAssets": true,
    "skipFeatureDeployment": true
  }
}

References


Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Written by

Nithin Mohan TK

Hello Namaste! 👋🏻 I'm an accomplished Enterprise Solution Architect & Engineering Leader with 20+ years of progressive experience architecting, building, and scaling transformative enterprise solutions. ⚜️ Solution Architect / AI & Cloud 📌 Galway, Ireland

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.