Skip to content

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-button
label: "+1"
hidden: true
id: "count-increment"
style: default
actions:
- type: updateMetadata
bindTarget: count
evaluate: true
value: "x + 1"
```
```meta-bind-button
label: "-1"
hidden: true
id: "count-decrement"
style: default
actions:
- type: updateMetadata
bindTarget: count
evaluate: true
value: "x - 1"
```
```meta-bind-button
label: "Reset"
hidden: true
id: "count-reset"
style: default
actions:
- 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: 35
max_health: 50
damage: 5
---
```meta-bind-button
label: "Deal"
style: destructive
hidden: true
id: "deal-damage"
actions:
- type: updateMetadata
bindTarget: health
evaluate: true
value: "x - getMetadata('damage')"
```
```meta-bind-button
label: "Reset"
style: primary
hidden: true
id: "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]`