Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/authoring/conditional.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ You can also set conditions on non-executable code blocks:
```
````

::: {.callout-tip title="Conditional Exectution with Knitr" collapse="true"}

When using the `knitr` engine, if you want to have an **executable** code chunk being executed/evaluated only when the output is being rendered to HTML or LaTeX you can use the `is_html_output()` and `is_latex_output()` respectively (see [this reply to quarto-cli issue 11724](https://github.com/quarto-dev/quarto-cli/issues/11724#issuecomment-2557635192)).

```` markdown
::: {.content-visible when-format="html"}

```{{r}}
#| eval: !expr knitr::is_html_output()
# code is shown AND evaluated only in HTML
2+2
```

:::
````
:::

To apply a condition only to a part of a paragraph, use a span (`[]{}`):

``` markdown
Expand Down Expand Up @@ -112,4 +129,4 @@ path:
````

This feature is often useful alongside [project profiles](/docs/projects/profiles.qmd).
Different profiles can set different metadata values, and so can control the metadata used in conditional content.
Different profiles can set different metadata values, and so can control the metadata used in conditional content.