- 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:
| Field | Output |
|---|---|
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"> |
baseOgImage | og: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 value | Creation time tag, from published | Update time tag, from updated |
|---|---|---|
article | article:published_time | article:modified_time |
book | book:release_date | — |
music.album | music:release_date | — |
video.movie | video:release_date | — |
video.episode | video: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:
-
Update
@sitecore-content-sdk/angularand its related SDK dependencies to compatible versions that exportScPageMetaTagsComponentandPageMetadataFields. -
In
src/app/shared/layout.component.ts, extend your route fields interface fromPageMetadataFieldsand type the route asRouteData<RouteFields>:When adapting this example, retain your existing component imports, layout markup, and other layout logic.
-
Remove any existing
Titleinjection and effect that callsTitle.setTitle(). Remove other code that manages the same metadata or Open Graph tags.
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:
| Input | Type | Description |
|---|---|---|
route | RouteData<PageMetadataRouteFields> | null | undefined | Route node from the layout response, typically page.layout.sitecore.route. |
defaultTitle | string | Fallback 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:
| Method | Description |
|---|---|
apply(route?: RouteData<PageMetadataRouteFields> | null, defaultTitle = 'Page'): void | Sets the title, removes previously managed metadata tags, and adds tags for the route. |
clear(): void | Removes 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:
- Populate the metadata and Open Graph fields on a Sitecore page and publish the changes.
- Request the page from your SSR server and inspect the returned HTML. Confirm that
<head>contains the expected title and tags. - 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.