diff --git a/docs/authoring/conditional.qmd b/docs/authoring/conditional.qmd index 33b11cafb..07c63811f 100644 --- a/docs/authoring/conditional.qmd +++ b/docs/authoring/conditional.qmd @@ -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 @@ -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. \ No newline at end of file +Different profiles can set different metadata values, and so can control the metadata used in conditional content.