8.2.3 • Published 17 days ago

ember-page-title v8.2.3

Weekly downloads
65,732
License
MIT
Repository
github
Last release
17 days ago

ember-page-title Ember Observer Score CI

This addon provides a helper for changing the title of the page you're on.

Installing via ember-cli

ember install ember-page-title

Compatibility

  • Ember.js v3.28 or above
  • Ember CLI v3.28 or above
  • Node.js v14 or above

Post Install Setup Notes

As of v3.0.0 this addon maintains the page title by using the <title> tag in your document's <head>. This is necessary for FastBoot compatibility.

Non-fastboot apps should keep the <title> tag in index.html to ensure that the initial page is valid HTML. The title will be removed and replaced when your app boots.

Fastboot apps MUST remove the <title> tag from index.html. As of v6.0.0 this is done automatically if you use ember install ember-page-title to install this addon. Can also be run manually using ember g ember-page-title to update the title if FastBoot is installed.

Digging in

Visit the Docs site

API

{{page-title}} Helper

attributetypedefaultdescription
separatorstring" \| "Which separator should be displayed after this instance of {{page-title}}
prependbooleantrueIf the token should be prepended or appended to the list of tokens
replacebooleanfalseReplace all previous elements with the active
frontbooleanfalseIf the token should always be in the beginning of the resulting title.

The default values for separator, prepend and replace are configurable via config/environment.js:

// config/environment.js

module.exports = function (environment) {
  let ENV = {
    pageTitle: {
      replace: true,
    },
  };

  return ENV;
};

For usage in gts and gjs, the pageTitle helper is exported from the index:

import { pageTitle } from 'ember-page-title';

<template>
  {{pageTitle "About"}}
  
  ...
</template>

page-title Service

If you want to be notified when the page title has been updated, you can extend and override the page-title service and provide your own titleDidUpdate hook. The titleDidUpdate hook receives the new title as its sole argument.

// app/services/page-title.js

import EmberPageTitleService from 'ember-page-title/services/page-title';

export default class PageTitleService extends EmberPageTitleService {
  titleDidUpdate(title) {
    // Do something with the new title.
  }
}

Testing

assert the page title with the supplied getPageTitle test helper:

import { getPageTitle } from 'ember-page-title/test-support';

module('Acceptance | Register Page', function (hooks) {
  setupApplicationTest(hooks);

  test('visiting /register', async function (assert) {
    const registerURL = '/register';
    await visit(registerURL);

    assert.equal(currentURL(), registerURL);
    assert.equal(getPageTitle(), 'Register | Some Website');
  });
});

TypeScript and Glint

If your project uses loose-mode templates, you can merge in the template registry interface provided by ember-page-title,

// <your-app>/types/glint.d.ts
import '@glint/environment-ember-loose';
import '@glint/environment-ember-template-imports';

import type PageTitle from 'ember-page-title/template-registry';

declare module '@glint/environment-ember-loose/registry' {
	export default interface Registry extends PageTitle {
        /* your local loose-mode entries here */
	}
}

Similarly, if you rely on a service registry, you'll want to import ember-page-title's service registry and extend from it.

import type PageTitle from 'ember-page-title/service-registry';

declare module '@ember/service' {
  interface Registry extends PageTitle {
        /* your local service entries here */
  }
}

or, if you wish to manage how the service becomes registered yourself, you may import the service:

import type PageTitle from 'ember-page-title/services/page-title';

Upgrading notes for 5.x to 6.x

  • ember-page-title no longer requires the usage of ember-cli-head. Please remove {{head-layout}} from your application's application.hbs route template.
  • {{title}} has been removed, please rename to {{page-title}}.

Contributing

Contributors are welcome! Please provide a reproducible test case. Details will be worked out on a case-per-case basis. Maintainers will get in touch when they can, so delays are possible. For contribution guidelines, see the code of conduct.

Publishing Documentation

To publish documentation, run the following command:

ember github-pages:commit --message "update documentation"
git push origin gh-pages:gh-pages
8.2.3

17 days ago

8.2.2

1 month ago

8.2.1

2 months ago

8.2.0

3 months ago

8.1.0

5 months ago

8.0.0-beta.1

8 months ago

8.0.0

8 months ago

8.0.0-beta.0

2 years ago

7.0.0

2 years ago

6.2.2

3 years ago

6.2.1

3 years ago

6.2.0

3 years ago

6.1.0

3 years ago

6.0.3

3 years ago

6.0.2

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.2.3

4 years ago

5.2.2

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.0

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.2.2

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.6

7 years ago

3.1.5

7 years ago

3.1.4

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.10

7 years ago

3.0.9

8 years ago

3.0.8

8 years ago

3.0.7

8 years ago

3.0.6

8 years ago

3.0.5

8 years ago

3.0.3

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.7

9 years ago

2.0.6

9 years ago

2.0.5

9 years ago

2.0.4

9 years ago