Can environment variables be access from OJS?
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, typescript
- Domain
- web-dev
Research direction
Start by creating the website project, setting TEST_VAR in _environment, and rendering index.qmd with the OJS examples. Compare the working Markdown, knitr, and vanilla JavaScript cases with the OJS and import.ts cases; done means the environment value is available as a string in OJS contexts.
Written by the indexing model from the issue text.
Description
Bug description
I've found I can use the env shortcode to access environment variables defined in _environment in lots of places, like static Markdown, vanilla JavaScript, and rendered code cells.
But it seems like the shortcode won't work in OJS. Any method I could think of quoting the shortcode leads to it not being interpolated, and interpolating it without quotes means it ends up as a bare symbol rather than a string. A knitr R chunk and a vanilla JavaScript block inside raw HTML both worked successfully. (I also tried @cscheid's trick of importing a TypeScript file, but I also had no luck there.)
(Note that I've attached a PDF printout of the page, but I get the same result in the browser itself — this isn't being introduced by the printout.)
Steps to reproduce
quarto create project (website), then:
_environment:
TEST_VAR=hello world
import.ts:
export const imported_var = `{{< env TEST_VAR >}}`
index.qmd:
---
title: "OJS Shortcode Test"
engine: knitr
---
My `TEST_VAR` works fine in static Markdown: {{< env TEST_VAR >}}
What about in a rendered code cell? Yup! (At least in knitr with R):
```{r}
print("{{< env TEST_VAR >}}")
```
And in vanilla JavaScript when wrapped in quotes (check the console to see it):
```{=html}
<script>
const test_var_js = "{{< env TEST_VAR >}}"
console.log("TEST_VAR IS:", test_var_js)
</script>
```
```{ojs}
md`But not in OJS! Here it is, interpolated into Markdown inside OJS: {{< env TEST_VAR >}}`
```
And again, inside an OJS braced function. This first example interpolates as expected, but of course we can't return a literal symbol, leading to an error:
```{ojs}
{
return {{< env TEST_VAR >}}
}
```
Wrapping in quotes, however, fails to interpolate:
```{ojs}
{
return "{{< env TEST_VAR >}}"
}
```
What about backticks?
```{ojs}
{
return `{{< env TEST_VAR >}}`
}
```
Or an expression inside Markdown?
```{ojs}
{
return md`${ {{< env TEST_VAR >}} }`
}
```
Again, interpolating, but no longer works because we now no longer have a quoted string.
Here's one final shot, short of just embedding the var in a `<meta>` tag in the page header — let's take advantage of [importing from a TypeScript file](https://github.com/quarto-dev/quarto-cli/discussions/11371#discussioncomment-11246537):
```{ojs}
import { imported_var } from "./import.ts"
imported_var
```
Alas, no.
For good measure, here's trying to use it with the unified inline syntax: `{ojs} {{< env TEST_VAR >}} }`
[OJS Shortcode Test.pdf](https://github.com/user-attachments/files/20156350/OJS.Shortcode.Test.pdf)
Actual behavior
No response
Expected behavior
No response
Your environment
- OS: MacOS 15.4.1
- VSCode 1.100.0
Quarto check output
Quarto 99.9.9
[✓] Checking environment information...
Quarto cache location: /Users/jimjamslam/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.6.3: OK
Dart Sass version 1.85.1: OK
Deno version 1.46.3: OK
Typst version 0.13.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 99.9.9
commit: 6202430787bc0787b97c19026cb96aa4e8a3ea19
Path: /Users/jimjamslam/code/tools/quarto-cli/package/dist/bin
[✓] Checking tools....................OK
TinyTeX: (not installed)
Chromium: (not installed)
[✓] Checking LaTeX....................OK
Tex: (not detected)
[✓] Checking Chrome Headless....................OK
Using: Chrome found on system
Path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Source: MacOS known location
[✓] Checking basic markdown render....OK
[✓] Checking Python 3 installation....OK
Version: 3.13.3
Path: /opt/homebrew/opt/python@3.13/bin/python3.13
Jupyter: (None)
Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter
[✓] Checking R installation...........OK
Version: 4.4.1
Path: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources
LibPaths:
- /Users/jimjamslam/Library/R/arm64/4.4/library
- /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
knitr: 1.49
rmarkdown: 2.29
[✓] Checking Knitr engine render......OK
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quarto-dev/quarto-cli
-
binder bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
quarto-dev/quarto-cli#14907 · 3 comments ·
-
brand bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
quarto-dev/quarto-cli#14891 ·
-
brand bug html revealjs
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
quarto-dev/quarto-cli#14882 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
quarto-dev/quarto-cli#14875 ·
-
Percent scripts: accept raw-string (r""") and '''-delimited markdown cells, as jupytext writes them Openengines-jupyter enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
quarto-dev/quarto-cli#14850 · 2 comments ·
All issues in quarto-dev/quarto-cli
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100