1. Developer guides

Generate page metadata and Open Graph tags

Content SDK for Angular can generate a page's <title>, standard metadata tags, and Open Graph tags from Sitecore route fields. The SDK uses Angular's Title and Meta services to add tags to the document head during server-side rendering (SSR) and update them during client-side navigation.

The SDK supports the following fields when present in route.fields:

FieldOutput
Title<title>. Falls back to the configured default when empty or absent.
baseMetadataTitle<meta name="title">. Doesn't affect <title>.
baseMetadataDescription<meta name="description">
baseMetadataKeywords<meta name="keywords">
baseMetadataAuthor<meta name="author">
baseOgTitle<meta property="og:title">
baseOgDescription<meta property="og:description">
baseOgImageog:image, og:image:width, og:image:height, and og:image:alt
baseOgType<meta property="og:type">

The mappings are independent; there is no cross-field fallback. For example, baseOgTitle doesn't fall back to Title, and baseOgDescription doesn't fall back to baseMetadataDescription. Empty or absent values omit their tags, except for <title>, which uses the default title.

The image tags use baseOgImage.value.src, width, height, and alt. The SDK only adds width, height, and alt tags when the image has a src value.

Open Graph time tags

When baseOgType identifies an Open Graph type with a defined time tag, the SDK maps the route's published and updated values, when available, to the following tags:

baseOgType valueCreation time tag, from publishedUpdate time tag, from updated
articlearticle:published_timearticle:modified_time
bookbook:release_date—
music.albummusic:release_date—
video.movievideo:release_date—
video.episodevideo:release_date—

Other types, such as website, don't produce time tags. The timestamps are properties of the route, not entries in route.fields.

Use the page metadata component

The Angular app template includes ScPageMetaTagsComponent in src/app/shared/layout.component.ts. Apps generated from a template that includes this component require no additional setup.

To add metadata generation to an existing app:

  1. Update @sitecore-content-sdk/angular and its related SDK dependencies to compatible versions that export ScPageMetaTagsComponent and PageMetadataFields.

  2. In src/app/shared/layout.component.ts, extend your route fields interface from PageMetadataFields and type the route as RouteData<RouteFields>:

    import { Component, computed, input } from '@angular/core';
    import {
      Field,
      Page,
      PageMetadataFields,
      RouteData,
      ScPageMetaTagsComponent,
    } from '@sitecore-content-sdk/angular';
    
    export interface RouteFields extends PageMetadataFields {
      [key: string]: unknown;
      Title?: Field<string>;
    }
    
    @Component({
      selector: 'app-layout',
      imports: [ScPageMetaTagsComponent],
      template: `
        <sc-page-meta-tags [route]="scRoute()" defaultTitle="Acme Store" />
        <!-- Keep your existing layout and placeholders here. -->
      `,
    })
    export class LayoutComponent {
      readonly page = input.required<Page>();
    
      readonly scRoute = computed(
        () => this.page().layout?.sitecore?.route as RouteData<RouteFields> | null
      );
    }

    When adapting this example, retain your existing component imports, layout markup, and other layout logic.

  3. Remove any existing Title injection and effect that calls Title.setTitle(). Remove other code that manages the same metadata or Open Graph tags.

Note

The component manages tags in the document head, not visible page content. Use one metadata component or service owner for the active page. Other code that changes the same tags can conflict with the SDK and have its changes overwritten or removed.

ScPageMetaTagsComponent accepts the following inputs:

InputTypeDescription
routeRouteData<PageMetadataRouteFields> | null | undefinedRoute node from the layout response, typically page.layout.sitecore.route.
defaultTitlestringFallback for <title> when the route has no non-empty Title value. Defaults to 'Page'.

The component reapplies metadata when its inputs change. Before adding the new route's tags, the SDK removes the metadata and Open Graph tags it manages. On destruction, the component removes those tags but leaves <title> unchanged.

If your previous layout used 'Content SDK Page' as its fallback title, set defaultTitle="Content SDK Page" to preserve that behavior. If you omit defaultTitle, the fallback changes to 'Page'.

Use the metadata service

For a custom layout or other code that doesn't use the component, inject PageMetadataService from @sitecore-content-sdk/angular:

MethodDescription
apply(route?: RouteData<PageMetadataRouteFields> | null, defaultTitle = 'Page'): voidSets the title, removes previously managed metadata tags, and adds tags for the route.
clear(): voidRemoves the managed metadata and Open Graph tags. Leaves <title> unchanged.

When using the service directly, call apply() when the route changes and clear() during the owning component's destruction. Don't use the service and component to manage the same page simultaneously.

For custom integrations that need resolved values without changing the document, use resolvePageMetadataFields(route, defaultTitle) from @sitecore-content-sdk/content/layout.

Verify the output

To check metadata generation:

  1. Populate the metadata and Open Graph fields on a Sitecore page and publish the changes.
  2. Request the page from your SSR server and inspect the returned HTML. Confirm that <head> contains the expected title and tags.
  3. Navigate to another page in the browser. Confirm that the SDK updates the title and metadata and removes tags with no value on the new page.

Structured data uses a separate component. See Render Schema.org structured data as JSON-LD.

If you have suggestions for improving this article, let us know!