Skip to content

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.
PropertyDescriptionTemplates where present
absoluteUrlThe complete URL currently displayed, including base URL (with prefix, if set) and query parameters.All pages Widgets
aposBodyDataAttributesA string of JSON that Apostrophe applies to the body tag as data attributes. Used by the UI app.All pages Widgets
baseUrlThe site's configured baseUrl value. Typically the website's domain.All pages Widgets
baseUrlWithPrefixThe baseUrl value, plus the site's prefix value, if set.All pages Widgets
bestPageUsually 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
contextOptionsAn object of context options, if passed in.Widgets
editAn alias of data.bestPage._edit, indicating whether the active user has editing permissions for the data.bestPage document.All pages
globalThe data object for the global doc.All pages Widgets
homeThe data object for the home page.All pages Widgets
localeThe active locale.All pages Widgets
localizationsAn array of active locales including information about the active page in each.All pages
managerIn widget templates, the widget module manager object.Widgets
nextIf next: true is set on the piece page type, the data object for the next piece in sort order.Show pages
optionsWidgets
outerLayoutA reference path to the outer layout template. Used in layout templates.All pages
pageA data object for the active page or the index page in show page templates.All pages Widgets
pieceThe piece data object in a show page template.Show pages
previousIf previous: true is set on the piece page type, the data object for the previous piece in sort order.Show pages
queryAn object of query parameters from the request URL.All pages
sceneA string indicating the active "scene," or general user context. Either 'public' or 'apos'.All pages
slugThe active page's slug.All pages
urlThe active page's full relative URL, including query parameters.All pages
userWhen a user is logged in, a data object for the active user. null if logged out.All pages Widgets
widgetThe widget data object in a widget template.Widgets