Skip to content

Commit

Permalink
docs: env vars in source queries and pages
Browse files Browse the repository at this point in the history
  • Loading branch information
archiewood committed Oct 2, 2024
1 parent 4347a47 commit 98ee007
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion sites/docs/pages/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,46 @@ N.B. Environment variables are **case sensitive**, so you should preserve the ca

### .env Files

Evidence will read in environment variables from a `.env` file in the root of your project. This is useful for local development.
Evidence will read in environment variables from a `.env` file in the root of your project. This is useful for local development.

### Environment Variables in Source Queries

Environment variables to be used in source queries should be prefixed with `EVIDENCE_VAR__` (note the double underscore). They can be used in source queries with `${EVIDENCE_VAR__variable_name}`.

```
EVIDENCE_VAR__customer_name="Acme Corporation"
```

```
select *
from orders
where customer_name = '${customer_name}'
```

The quotes would be omitted if the variable was not a string.

### Environment Variables in Pages

Environment variables to be used in pages should be prefixed with `VITE_`. They can be accessed with `import.meta.env.VITE_variable_name`.

`.env`
```bash
VITE_customer_attribute=premium
```

`index.md`
```html
<script>
const customer_attribute = import.meta.env.VITE_customer_attribute;
</script>

{#if customer_attribute === 'premium'}

premium

{:else if customer_attribute === 'free'}

free

{/if}
```

0 comments on commit 98ee007

Please sign in to comment.