URL Helpers

These helpers expose resolved URL values to Handlebars expressions and attributes that are not automatically treated as URLs. For the meaning of /, ~/, and ordinary relative paths, see URL resolution.

HelperPurposeParametersReturns
rootUrlReturns the documentation-root URLuri
rootRelativeUrlResolves a path from the documentation rooturiuri
fragmentExtracts fragment (anchor) from a URL for linking to sectionsuristring?

rootUrl

Provides the documentation-root URL for the page currently being rendered. This can be an absolute URL or a sequence of parent segments such as ../../.

Syntax:

{{#rootUrl}}

Returns: A URI object that is either absolute or relative to the current page, depending on the context

Examples:

{{#rootUrl}}    {{!-- Absolute: "https://example.github.io/project/" --}}
{{#rootUrl}}    {{!-- Relative: "../../" --}}

Use this helper when the root URL is needed as data rather than as an href or src value, for example:

<nav data-base-url="{{#rootUrl}}"></nav>

rootRelativeUrl

Resolves a path from the documentation root for the page currently being rendered.

Syntax:

{{#rootRelativeUrl uri}}

Parameters:

Returns: A URL string that is either absolute or relative to the current page, depending on the context

Examples:

{{#if (eq model.url (rootRelativeUrl "index.html"))}}
  Home page
{{/if}}

<link rel="icon" href="{{#rootRelativeUrl faviconUri}}" />

Use this helper for documentation-root-relative URLs in Handlebars templates. The ~/ marker is resolved in conceptual topics and Markdown theme settings, but it is not expanded in raw template output.

fragment

Extract the fragment identifier of a URL for linking to specific sections.

Syntax:

{{#fragment url}}

Parameters:

Returns: URL fragment string (without # prefix)

Examples:

{{#fragment "example/best-practices.html#cs"}}        {{!-- "cs" --}}
<h1 id="{{#fragment model.url}}">{{model.name}}</h1>