ember-page-title provides comprehensive page title management for Ember.js applications, enabling dynamic title updates through template helpers and programmatic APIs. It offers declarative template syntax with configurable separators, prepend/append behavior, and token replacement, along with a service for advanced integration scenarios.
ember install ember-page-title// Template helper import (for gts/gjs templates)
import { pageTitle } from 'ember-page-title';
// Service import
import PageTitleService from 'ember-page-title/services/page-title';
// Test support
import { getPageTitle } from 'ember-page-title/test-support';For traditional Ember app imports:
// Service injection
@service('page-title') pageTitle;
// Test helper import
import { getPageTitle } from 'ember-page-title/test-support';// In gts/gjs templates
import { pageTitle } from 'ember-page-title';
<template>
{{pageTitle "My Page Title"}}
{{pageTitle @model.title separator=" - "}}
{{pageTitle "Settings" prepend=false}}
</template>Traditional Handlebars templates:
{{page-title "My Page Title"}}
{{page-title @model.title separator=" - "}}
{{page-title "Settings" prepend=false}}ember-page-title is built around several key components:
{{page-title}} helper for setting titles in templates with automatic lifecycle managementpage-title service managing title tokens, inheritance, and DOM updatesDeclarative helper for setting page titles in templates with automatic registration and cleanup. Supports configurable separators, positioning, and replacement behavior.
interface PageTitleHelperOptions {
prepend?: boolean;
front?: unknown;
replace?: boolean;
separator?: string;
}
interface PageTitleHelperSignature {
Args: {
Positional: string[];
Named: PageTitleHelperOptions;
};
Return: void;
}Programmatic API for managing page titles with token-based system, inheritance, and lifecycle hooks. Provides fine-grained control over title composition and update callbacks.
class PageTitleService {
tokens: PageTitleToken[];
push(token: PageTitleToken): void;
remove(id: string): void;
scheduleTitleUpdate(): void;
toString(): string;
titleDidUpdate(title: string): void;
willDestroy(): void;
get visibleTokens(): PageTitleToken[];
get sortedTokens(): PageTitleToken[];
}Testing utilities for asserting page titles in integration and acceptance tests, with automatic handling of test environment quirks.
function getPageTitle(doc?: Document): string;Complete TypeScript definitions with Glint template registry and service registry integration for type-safe template and service usage.
interface LooseModeTemplateRegistry {
'page-title': typeof pageTitle;
}
interface ServiceRegistry {
'page-title': PageTitleService;
}Configure defaults in config/environment.js:
module.exports = function(environment) {
let ENV = {
pageTitle: {
separator: ' | ', // Default separator between title tokens
prepend: true, // Default prepend behavior
replace: false // Default replace behavior
}
};
return ENV;
};interface PageTitleConfig {
/** The default separator to use between tokens. */
separator?: string;
/** The default prepend value to use. */
prepend?: boolean;
/** The default replace value to use. */
replace?: boolean | null;
}
interface PageTitleToken extends PageTitleConfig {
id: string;
title?: string;
separator?: string;
prepend?: boolean;
replace?: boolean;
front?: unknown;
previous?: PageTitleToken | null;
next?: PageTitleToken | null;
}