Fix object decorator docs

pull/1003/head
Zef Hemel 2024-07-30 11:46:22 +02:00
parent 75471fa86b
commit 704e318229
2 changed files with 10 additions and 3 deletions

View File

@ -15,7 +15,8 @@ objectDecorators:
<<attributePath>>: '<<value expression>>' <<attributePath>>: '<<value expression>>'
``` ```
**Note:** To make changes take effect you may have to reload your client (just refresh the page). > **note** Note
> For changes to take effect you may have to reload your client (just refresh the page).
A few things of note: A few things of note:
@ -26,8 +27,14 @@ A few things of note:
* `pageDecoration.prefix` * `pageDecoration.prefix`
* `<<value expression>>` like `<<expression>>` must be a YAML string-encoded expression using the [[Expression Language]], some examples together with the attribute path: * `<<value expression>>` like `<<expression>>` must be a YAML string-encoded expression using the [[Expression Language]], some examples together with the attribute path:
* `alwaysTen: '10'` (attaches an attribute named `alwaysTen` with the numeric value `10` to all objects matching the `where` clause) * `alwaysTen: '10'` (attaches an attribute named `alwaysTen` with the numeric value `10` to all objects matching the `where` clause)
* `alwaysTrue: 'true'` (same as `alwaysTen` but with a boolean value)
* `fullName: 'firstName + " " + lastName'` (attaches a `fullName` attribute that concatenates the `firstName` and `lastName` attributes with a space in between) * `fullName: 'firstName + " " + lastName'` (attaches a `fullName` attribute that concatenates the `firstName` and `lastName` attributes with a space in between)
* `nameLength: 'count(name)'` (attaches an attribute `nameLength` with the string length of `name` — not particularly useful, but to demonstrate you can call [[Functions]] here too) * `nameLength: 'count(name)'` (attaches an attribute `nameLength` with the string length of `name` — not particularly useful, but to demonstrate you can call [[Functions]] here too)
## Rules
A few rules to keep things civil:
* Dynamic attributes _cannot override already existing attributes_. If the object already has an attribute with the same name, this value will be kept as is.
* For performance reasons, all expressions (both filter and value expressions) need to be _synchronously evaluatable_. * For performance reasons, all expressions (both filter and value expressions) need to be _synchronously evaluatable_.
* Generally, this means they need to be “simple expressions” that require no expensive calls. * Generally, this means they need to be “simple expressions” that require no expensive calls.
* Simple expressions include simple things like literals, arithmetic, calling some of the cheap [[Functions]] such as `today()` or string manipulation functions. * Simple expressions include simple things like literals, arithmetic, calling some of the cheap [[Functions]] such as `today()` or string manipulation functions.

View File

@ -25,7 +25,7 @@ For the purposes of [[Page Decorations]], let us limit simply to some useful exa
## Example: page prefix ## Example: page prefix
Lets say we want to put a 🧑 prefix on every page tagged with `#person`. We can achieve this as follows in our [[^SETTINGS]]: Lets say we want to put a 🧑 prefix on every page tagged with `#person`. We can achieve this as follows in our [[^SETTINGS]]:
```yaml ```yaml
objectDecorations: objectDecorators:
- where: "tags = 'person'" - where: "tags = 'person'"
pageDecoration.prefix: '"🧑 "' pageDecoration.prefix: '"🧑 "'
``` ```
@ -38,7 +38,7 @@ Lets say that adding this `pageDecoration.disableTOC` to the front matter is
You can do this as follows: You can do this as follows:
```yaml ```yaml
objectDecorations: objectDecorators:
- where: 'tags = "notoc"' - where: 'tags = "notoc"'
attributes: attributes:
pageDecoration.disableTOC: "true" pageDecoration.disableTOC: "true"