Property object¶
Property objects are retrieved using the props attribute.
These are used inside of templates.
Examples¶
Here's an example you might use while adding metadata to your page:
---
{% for prop in page.props %}
{{ prop.name }}: {{ prop.value }}
{% endfor %}
---
Here's an example setting specific locations for certain properties:
---
Name: {{ page.props['Name'].value }}
Amount: {{ page.props['Amount'].value }}
Tags: {{ page.props['Tags'].value }}
---
Property names pre-pended with back-slashes¶
Property names will output as closely as possible to how they are in Notion, though for some reason, certain characters aren't allowed at the beginning of YAML property names.
If this happens, the property name will be pre-pended with a backslash (\
).
This happens with the following characters:
- *
- >
- {
- }
- @
- "
- #
For example, original:
#Y@L@#: value
Filtered:
\#Y@L@#: value
Attributes¶
A property object will always contain these attributes:
Attribute | Type | Returns |
---|---|---|
name | String | The property's name |
value | String | A single string representing the property's value(s) (separated by ", " when multiple) |
values | List<String> | A list of the property's value(s) |
yaml | String | The property's YAML-formatted string (property-name: value ) |
Methods¶
A property object will always contain these methods:
Method | Return Type | Returns |
---|---|---|
get_name | String | The property's name |
get_value | String | A single string representing the property's value(s) (separated by ", " when multiple) |
get_values | List<String> | A list of the property's value(s) |
get_yaml | String | The property's YAML-formatted string (property-name: value ) |
Filtering characters and words from property names¶
To filter characters and words from property names, you can use the filter_name
parameter.
This works a little differently than simply replacing text characters, as it will filter the characters before any necessary YAML filtering is applied, such as pre-pending names with back-slashes.
For example:
prop.get_yaml(filter_name="*@🤗")
This will filter out all asterisks, @ symbols, and hug face emojis.
This can also work with a list instead, so you can filter out longer strings as well:
prop.get_yaml(filter_name=['*', '@', '🤗', 'hello'])
This will filter out all asterisks, @ symbols, hug face emojis, and any 'hello' words.
Getting tags or links for select property values¶
By default, when the selects_as
parameter is absent, Select, Status, and Multi-Select properties will simply return their values as strings.
To change how these values are rendered, you can use a selects_as
parameter and set this to either "tags" or "links".
For example:
prop.get_value(selects_as="tags")
When used by other properties, this parameter is ignored.
Date Property Objects¶
For date properties that use single values (created time, last edited time), these dates can be accessed using:
Attribute | Type | Returns |
---|---|---|
value | String | The value_arrow formatted as "YYYY-MM-DDTHH-mm-ss" (same as Obsidian default) |
value_arrow | Arrow Object | The property's value (UTC) as an arrow object |
For dates that have a start and/or an end value, these dates can be accessed using:
Attribute | Type | Returns |
---|---|---|
value | String | If property only has a start, "start", else "start -> end" |
value_end | String | The value_end_arrow formatted as "YYYY-MM-DDTHH-mm-ss" (same as Obsidian default) |
value_end_arrow | Arrow Object | The property's end datetime (UTC) as an arrow object |
value_start | String | The value_start_arrow formatted as "YYYY-MM-DDTHH-mm-ss" (same as Obsidian default) |
value_start_arrow | Arrow Object | The property's start datetime (UTC) as an arrow object |
Formatting datetime properties using a different format¶
You are able to format datetime properties using the format method:
Created: {{ page.props['Created'].value_arrow.format('YYYY-MM-DD HH:mm') }}
This YYYY-MM-DD HH:mm
format is part of the ISO 8601 standard. format()
will accept any string which uses this standard. Refer to this format reference.
Getting datetime properties to return a datetime in a different timezone¶
By default, datetime properties are stored in Notion as UTC; 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, you can use the timezone
parameter.
The timezone
parameter effectively acts as an hour modifier, and is ignored in non-datetime properties.
For example, if you are from the US/Pacific (UTC-8) timezone, you can use this code:
{% for name, prop in page.props.items() %}
{{ prop.get_yaml(timezone=-8) }}
{% endfor %}
This changes all datetime properties to return a string 8 hours behind the UTC datetime.