Template data
All Apostrophe template files have access to a data
object. It contains content data as well as additional information such as the page's URL and the active user. Some properties differ depending on the template type (e.g., data.widget
is only available in widget templates).
The table below lists the data properties available from Apostrophe core as well as the template types where they are available.
INFO
Template type indicators:
- All pages: The property is present in all page templates, including piece index pages and show pages.
- Show pages: The property is present in piece show page templates and not in other normal page templates.
- Widgets: The property is present in widget templates.
Property | Description | Templates where present |
---|---|---|
absoluteUrl | The complete URL currently displayed, including base URL (with prefix, if set) and query parameters. | All pages Widgets |
aposBodyDataAttributes | A string of JSON that Apostrophe applies to the body tag as data attributes. Used by the UI app. | All pages Widgets |
baseUrl | The site's configured baseUrl value. Typically the website's domain. | All pages Widgets |
baseUrlWithPrefix | The baseUrl value, plus the site's prefix value, if set. | All pages Widgets |
bestPage | Usually the same as data.page . If no page is found for the URL (e.g., a 404 page) it will be the data object for the page that best matches the slug, going back to the home page. | All pages Widgets |
contextOptions | An object of context options, if passed in. | Widgets |
edit | An alias of data.bestPage._edit , indicating whether the active user has editing permissions for the data.bestPage document. | All pages |
global | The data object for the global doc. | All pages Widgets |
home | The data object for the home page. | All pages Widgets |
locale | The active locale. | All pages Widgets |
localizations | An array of active locales including information about the active page in each. | All pages |
manager | In widget templates, the widget module manager object. | Widgets |
next | If next: true is set on the piece page type, the data object for the next piece in sort order. | Show pages |
options | Widgets | |
outerLayout | A reference path to the outer layout template. Used in layout templates. | All pages |
page | A data object for the active page or the index page in show page templates. | All pages Widgets |
piece | The piece data object in a show page template. | Show pages |
previous | If previous: true is set on the piece page type, the data object for the previous piece in sort order. | Show pages |
query | An object of query parameters from the request URL. | All pages |
scene | A string indicating the active "scene," or general user context. Either 'public' or 'apos' . | All pages |
slug | The active page's slug. | All pages |
url | The active page's full relative URL, including query parameters. | All pages |
user | When a user is logged in, a data object for the active user. null if logged out. | All pages Widgets |
widget | The widget data object in a widget template. | Widgets |