Skip to content

feat: add write_yaml_metadata_block()#16

Open
juleswg23 wants to merge 1 commit intoquarto-dev:mainfrom
juleswg23:feat-write-yaml-metadata-block
Open

feat: add write_yaml_metadata_block()#16
juleswg23 wants to merge 1 commit intoquarto-dev:mainfrom
juleswg23:feat-write-yaml-metadata-block

Conversation

@juleswg23
Copy link

@juleswg23 juleswg23 commented Feb 24, 2026

Description

We replicate the behavior of the quarto-r equivalent: https://quarto-dev.github.io/quarto-r/reference/write_yaml_metadata_block.html

This intends to support one path for injecting recipients into email document metadata, to support quarto-dev/quarto-cli#14098

Manual testing

We can verify this behavior works by rendering the below document

---
title: "Dynamic Metadata Example"
format: html
---

## Basic Usage

Set metadata dynamically from Python:

```{python}
#| output: asis
from quarto import write_yaml_metadata_block

write_yaml_metadata_block(
  admin=True,
  user_level="advanced",
  version="1.0"
)
```

## Using Conditional Content

Now we can use the dynamically set metadata:

::: {.content-visible when-meta="admin"}
This content is only visible when admin=true!
:::

::: {.content-hidden when-meta="admin"}
This content is hidden when admin=true.
:::

## Dynamic Computation

Compute values in Python and use them as metadata:

```{python}
#| output: asis
from quarto import write_yaml_metadata_block
import datetime

today = datetime.date.today()
is_weekend = today.weekday() >= 5

write_yaml_metadata_block(
  date=str(today),
  is_weekend=is_weekend,
  day_name=today.strftime("%A")
)
```

::: {.content-visible when-meta="is_weekend"}
It's the weekend!
:::

::: {.content-hidden when-meta="is_weekend"}
It's a weekday.
:::

@juleswg23 juleswg23 changed the title add function to mimic the behavior of quarto-r write_yaml_metadata_block feat: add write_yaml_metadata_block() Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant