-
下面是一个符合 Quarto 官方 Bug Report 指南的英文问题提问模板,基于你原来的问题和你提供的信息(Python 3.9、VSCode、Jupyter 环境)重写而成: Title: External parameter not passed to title/subtitle when rendering to DOCX using Quarto 🐛 Bug ReportSummaryI’m trying to pass external parameters to dynamically generate the document title and subtitle in a 🔁 Minimal, self-contained, reproducible example---
title: "{{< meta params.mytitle >}}"
subtitle: "{{< meta params.mysubtitle >}}"
format:
docx:
reference-doc: word_temp.docx
default-image-extension: svg
params:
datapath: null
mytitle: "Default Title"
mysubtitle: "Default Subtitle"
engine: jupyter
jupyter: python3
---
```{python}
#| tags: [parameters]
# Placeholder for data path usage
print("Data path:", datapath)
``` Command used to render: quarto render rest_rep_v1.qmd \
-P datapath:"/some/path" \
-P mytitle:"Test Hospital" \
-P mysubtitle:"fNIRS Report" \
--no-cache Expected: Actual: 💻 Environmentquarto check
📌 QuestionIs there a recommended way to pass Any suggestions are greatly appreciated! I came across a couple of related issues that seem to suggest parameter substitution may not work reliably inside the title or subtitle fields: From those discussions, it seems that the title field might not fully support dynamic variable substitution (such as {{< meta ... >}} or {{params.xxx}}) in all formats or contexts. Could this be the root cause of the issue I'm experiencing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for the discussion. I found that the following approach seems to work: ---
title: "{{< env MY_TITLE >}}"
subtitle: "{{< env MY_SUBTITLE >}}"
format:
docx:
reference-doc: word_temp.docx
default-image-extension: svg
params:
datapath: null
# ... other settings ...
--- And I render the document with: MY_TITLE="test title" MY_SUBTITLE="try subtitle" quarto render /rest_rep_v1.qmd \
-P datapath:"{file_path}" \
--no-cache This successfully injects the dynamic title and subtitle via environment variables. However, I’m not sure whether relying on environment variables is the best practice, especially for reproducibility and clarity. Personally, I’d prefer a parameter-based solution (i.e., using I've already reviewed all GitHub issues and discussions related to Does anyone have a recommended or more idiomatic way to achieve this? |
Beta Was this translation helpful? Give feedback.
quarto render index.qmd --metadata title:"my title"
should also work, but be aware thattitle
is one of the structural option and is not a standard metadata as it is used in many parts.You should not try to dynamically modify the title when in a Quarto project (book, website, etc.).
Side effects should be limited in single document project.
You can see in the "metadata" block at render time that it does not show your modified title.