Update Metadata
The update metadata action allows you to update a specific property specified via a Bind Target. This property can be any valid Bind Target such as the frontmatter of a file.
interface UpdateMetadataButtonAction { type: 'updateMetadata'; bindTarget: string; // the bind target of the property to update evaluate: boolean; // whether to treat the value as a JavaScript expression value: string; // the value to set the property to or the JavaScript expression to evaluate}
If evaluate
is set to true
, the value is treated as a JavaScript expression and evaluated.
The current value of the property is available in the expression as x
.
Other properties can be reference using getMetadata(bindTarget)
where bindTarget
is a Bind Target string.
Example
This button group allows you to increment, decrement, and reset a counter stored in the frontmatter of the current file.
```meta-bind-buttonlabel: "+1"hidden: trueid: "count-increment"style: defaultactions: - type: updateMetadata bindTarget: count evaluate: true value: "x + 1"```
```meta-bind-buttonlabel: "-1"hidden: trueid: "count-decrement"style: defaultactions: - type: updateMetadata bindTarget: count evaluate: true value: "x - 1"```
```meta-bind-buttonlabel: "Reset"hidden: trueid: "count-reset"style: defaultactions: - type: updateMetadata bindTarget: count evaluate: false value: 0```
`BUTTON[count-decrement, count-reset, count-increment]` `VIEW[{count}]`
This is a simple health tracker for e.g. a TTRPG.
---health: 35max_health: 50damage: 5---
```meta-bind-buttonlabel: "Deal"style: destructivehidden: trueid: "deal-damage"actions: - type: updateMetadata bindTarget: health evaluate: true value: "x - getMetadata('damage')"```
```meta-bind-buttonlabel: "Reset"style: primaryhidden: trueid: "reset-health"actions: - type: updateMetadata bindTarget: health evaluate: true value: "getMetadata('max_health')"```
Health: `VIEW[{health}][text]` `BUTTON[reset-health]`
Damage: `INPUT[number:damage]` `BUTTON[deal-damage]`