Page Object

The Page Object is accessed using the page keyword inside of Templates.

This enables you to get information from the page this template is rendering.

There are four types of pages this page object could be:

  • Page (type="page");
  • Database (type="database");
  • Synced Block Page (type="page_syncblock"); and
  • Template Page (type="page_template").

Page Object Example

notion_url: {{ page.notion_url }}

This will render the page's Notion URL after the notion_url: in your template.


Attributes

The Page Object has the following attributes:

Attribute Return Type Returns
contents String The page's contents
cover Cover Object The page's cover object
created_time String The page's created time (UTC) formatted as "YYYY-MM-DDTHH-mm-ss" (same as Obsidian default)
created_time_arrow Arrow Object The page's created time (UTC) as an Arrow object
database Page Object Gets the page object of the database this page belongs to
icon String The page's icon (only supports emojis)
id String The page's short Notion ID (no hyphens '-')
last_edited_time String The page's last edited time (UTC) formatted as "YYYY-MM-DDTHH-mm-ss" (same as Obsidian default)
last_edited_time_arrow Arrow Object The page's last edited time (UTC) as an Arrow object
link String The link for this page.
link_display_text String The link display text.
notion_url String The Notion URL of the page
notion_url_short String The shortened Notion URL of the page
props Dictionary<String, Property Object> The page's property objects, keyed by property name
title String The page's title (if above 256 characters, returns first sentence or gives page ID instead)
title_file_safe String The page's file-safe title (replaces file-incompatible characters with equivalents)
title_unique String The page's unique title (same as title, except adds number on duplicate)
title_yaml String The page's title optimised for YAML (creates new-line formatted YAML sequence if necessary)
type String The page type: ("page", "database", "page_syncblock", "page_template")

Methods

The Page Object has an equivalent method available for every attribute.

This can be fetched using get_contents(), get_cover() etc.

Changing the timezone for created_time or last_edited_time

Notion stores created_time and last_edited_time as UTC times; this is useful if you're regularly switching timezone and want to always retrieve the same time relative to your own, though can be problematic if you want to import these times in your local timezone.

To resolve this, we have implemented a timezone parameter for get_created_time(), get_last_edited_time() and their datetime equivalents.

This parameter effectively acts as an hour modifier to your date.

For example, if you are from the US/Pacific (UTC-8) timezone, you can change this like this:

---
created: page.get_created_time(timezone=-8)
updated: page.get_last_edited_time(timezone=-8)
---

These will give you times that are 8 hours behind the UTC time stored in Notion.


Attributes

contents

For a page, contents returns the page's contents.

For a database, contents returns a markdown list with a link to every database object.

cover

The cover attribute returns a cover object.

The link for this page.

This includes all of the formatting magic that goes into the link display text.

Removes links within the title:

Hello [[Bob]]
Hello Bob

Replaces the following characters:

Character Replacement
[ (
] )
| -

Joins the title into a single-line:

Hello
Bob
Hello Bob

props

The props attribute returns an empty dictionary by default.

If this is a page inside a database, this returns a dictionary of property objects, keyed by the property name.

title_file_safe

The title_file_safe attribute grabs the page's title property and:

  1. De-linkifies any links from the title, showing only the display text for those links.
  2. Replaces any file-incompatible and link-breaking characters ( * " \ / < > : | ? ) with equivalents.

disallowed in filename characters

Character Replacement
*
" '
\ _
/ _
< (
> )
: -
| -
?
Character Replacement
[ (
] )
#
^

This is used by default in the title box.